Firebase,发送消息到特定平台(Android) [英] Firebase, send message to specific platform (Android)

查看:121
本文介绍了Firebase,发送消息到特定平台(Android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firebase允许我们通过接受我们的发布请求发送消息:

  {data:{
得分:5x1,
time:15:10
},
to:bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1 ...
}

但是,文档中显示的所有示例都是针对特定用户的。这需要他们的注册密钥。



在Firebase仪表板中,我们可以通过选择特定的平台将消息发送到设备。

什么样的参数需要为特定的应用程序包发送消息?



例如: kz.mycompany.myapp $ / $> $ / $>


  1. 到特定设备

  2. 到设备组


新的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:

  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 };

这篇关于Firebase,发送消息到特定平台(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆