Firebase, send message to specific platform (Andro

2019-05-18 15:14发布

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条回答
对你真心纯属浪费
2楼-- · 2019-05-18 15:47

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 };
查看更多
登录 后发表回答