2

As I have said in the title, I can't understand how notifications works when data is changed in Firestore. I have an app that requires notifications to a certain group of users when data is added or existing documents are changed in the database.

I understand how notification channels work with the UI but not how to setup my app to respond to changes in the database in the background when the app isn't running. I can send a notification directly from the console in FireStore. The issue is as stated when data changes in the database. I'm coding in Android Studio with Java.

Shreemaan Abhishek
  • 1,134
  • 1
  • 7
  • 33

1 Answers1

2

Here is a similar question, following: the highlights.

I think you might consider use Cloud Functions for Firebase. This will help you notify users when something interesting happens in the database. In order to make it work, you need to implement Firebase Authentication. This will help you send notifications to a particular user or to a group of users when something new happens.

Here is a straightforward example of how you can write the Node.js function.

Once a new notification appears, you can use sendToDevice function and the tokenId to send the notification to a specific user. The notification will be handled by the Android system and will be displayed to the user. Note, this will work only when the app is in background. You can receive notifications also when the app is in the foreground by implementing FirebaseMessagingService.

There is also explained in one tutorial step by step, how you can send notifications as you need to.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Joss Baron
  • 1,441
  • 10
  • 13