I am developing an android app using Firebase. Can Firebase send push notifications automatically when a record inserted to a table or I must implement my own server.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Since the 9th of march 2017 Firebase introduced “Firebase Functions”.It helps to trigger some events on specific dataset changes.These events could be then available in the Firebase Notifications Console to trigger the push Notification.
Take a look at https://firebase.googleblog.com/2017/03/introducing-cloud-functions-for-firebase.html
回答2:
Firebase provides push notification but not on database table changes. What you can do, you can create listeners in a background service and fire a notification from those listeners.
For instance, for listening to changes in 'User' node.
FirebaseDatabase myFirebaseRef = FirebaseDatabase.getInstance();
DatabaseReference myRef = myFirebaseRef.getReference("User");
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//put your notification code here
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.i("FirebaseError", databaseError.getMessage());
}
};
myRef.addValueEventListener(valueEventListener);