问题
I have an application which sends notification for multiple users at a time(not all user). So how to do this using Firebase Push Notification?
回答1:
You can use Topic Messaging
Based on the publish/subscribe model, FCM topic messaging allows you to send a message to multiple devices that have opted in to a particular topic.
Topic messaging supports unlimited topics and subscriptions for each app.
To subscribe to a topic, the client app calls Firebase Cloud Messaging subscribeToTopic() with the FCM topic name:
FirebaseMessaging.getInstance().subscribeToTopic("news");
To send a notification on topic :
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to": "/topics/news",
"data": {
"message": "This is a Firebase Cloud Messaging Topic Message!",
}
}
Read more at here : https://firebase.google.com/docs/cloud-messaging/android/topic-messaging
回答2:
To send notification to multiple users, you need to register the users a single topic
example topic called Weather
, then all users registered will get a notification.
To be able to send the push notification, you can use cloud functions:
Cloud Functions for Firebase 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. There's no need to manage and scale your own servers.
more info here: https://firebase.google.com/docs/functions/
来源:https://stackoverflow.com/questions/49188386/how-to-send-firebase-notification-for-all-user-at-a-time