I am trying to create an android application and would like to use firebase database. As I read firebase allows instant messaging and also notify clients when database is updated. I need to create a database and when any database changes happen, related users needs to be notified only. Is that possible with firebase or should I use backend server for this purpose?
Using FCM Console To send a notification, go to Firebase Console → Cloud Messaging and click on Send your first message. Then enter the Title and body field. If you wish to send it to a particular device then click on Send test message and enter the FCM registration token.
You can do it using the Firebase only. What you needs are
You should write two side codes:
In Client side (Android)
I recommend that you can store the token into the database/firestore too. for example:
class User { long id; String email; String token; }
You may write the code to modify the database/firestore.
Implement receiving code (https://firebase.google.com/docs/cloud-messaging/android/receive)
In Server side (Cloud Functions)
You can get the sample code for Server side (Cloud Functions) https://github.com/firebase/functions-samples/tree/master/fcm-notifications
Yes you can achieve this using Firebase Cloud Functions which:
lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your code is stored in Google's cloud and runs in a managed environment.
And with Firebase Cloud Messaging which:
Is a cross-platform messaging solution that lets you reliably deliver messages at no cost. Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user re-engagement and retention.
So you can write a function in Firebase Cloud Functions
which will trigger a notification every time something is changing in your database. Both documetations are very well explained.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With