Firebase,发送消息到特定平台(Android) [英] Firebase, send message to specific platform (Android)
问题描述
{data:{
得分:5x1,
time:15:10
},
to:bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1 ...
}
但是,文档中显示的所有示例都是针对特定用户的。这需要他们的注册密钥。
在Firebase仪表板中,我们可以通过选择特定的平台将消息发送到设备。
什么样的参数需要为特定的应用程序包发送消息?
例如: kz.mycompany.myapp $ c $使用Firebase云消息传递,您可以通过几种方式解决向其发送消息的方法:$ / $> $ / $> $ / $>
- 到特定设备
- 到设备组
新的Firebase控制台中的Firebase通知标签使用#1或#2发送给用户组。
但是看起来你要找的东西最容易通过发送到一个主题来实现:
FirebaseMessaging messaging = FirebaseMessaging.getInstance()
messaging.subscribeToTopic(package_kz_mycompany_myapp);然后你的服务器代码可以推送消息到这个主题,让它到达所有订阅了的设备主题:
var topic ='/ topics / package_kz_mycompany_myapp';
var data = {data:{
score:5x1,
time:15:10
},
to:话题 };
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
解决方案 With Firebase Cloud Messaging, you have a few ways to address to whom messages are sent:
- to a specific device
- to a device group
- 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 };
这篇关于Firebase,发送消息到特定平台(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!