Firebase, send message to specific platform (Android)

丶灬走出姿态 提交于 2019-12-07 22:54:48

问题


Firebase allows us to send messages by accepting our post requests:

{ "data": {
   "score": "5x1",
   "time": "15:10"
},
   "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}

However, all examples which are shown in their docs are for specific users. That requires their registration keys.

In Firebase Dashboard we can send messages to devices by choosing specific platform.

What kind of parameter is required in order to send message for specific application package?

for example: kz.mycompany.myapp


回答1:


With Firebase Cloud Messaging, you have a few ways to address to whom messages are sent:

  1. to a specific device
  2. to a device group
  3. to a topic

The Firebase Notifications tab in the new Firebase Console uses either #1 or #2 to send to groups of users.

But it looks like what you are looking for can be most easily accomplished by sending to a topic:

FirebaseMessaging messaging = FirebaseMessaging.getInstance()
messaging.subscribeToTopic("package_kz_mycompany_myapp");

Then your server-code can push messages to this topic to have it reach all devices that have subscribed to the topic:

var topic = '/topics/package_kz_mycompany_myapp';
var data = { "data": {
               "score": "5x1",
               "time": "15:10"
           },
           to : topic };


来源:https://stackoverflow.com/questions/37429448/firebase-send-message-to-specific-platform-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!