Reputation: 21
This is the structure of my app's data in which user can log in and post the image with image's detail in the database. I want that if a user post image, every user can see the notification Seth Post Something I cannot find any link how to send a notification to all users when new data is added. Can anyone specify the roadmap, code snippet how to do this after configuration of FCM
Upvotes: 2
Views: 3268
Reputation: 935
To achieve your requirement you can use cloud function to send messages to all devices and the steps to achieve this.
Fcm Tutorial, cloud function Tutorial and this tutorial is very helpful for me.
Upvotes: 1
Reputation: 753
First thing to do is registering your users to one topic.
FirebaseMessaging.getInstance().subscribeToTopic("MySampleApp");
Then send a post request to fcm api https://fcm.googleapis.com/fcm/send
//HEADERS
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GB,./,Udno5aA
//BODY
{
"to": "/topics/MySampleApp",
"data": {
"message": "Hello Everyone!",
}
}
Then handle the notification in your FirebaseMessagingService. Hope this helps
Upvotes: 0