android - 使用 Firebase 向所有已注册设备发送推送通知的 JSON 数据

标签 android firebase push-notification firebase-cloud-messaging

当我需要使用 Firebase 将通知发送到特定设备时,这是 JSON 结构。那么我应该如何修改它以向所有设备或几个选定的设备发送相同的通知?

{ "notification": {
    "title": "Quiz App",
    "text": "Your Quiz has submitted Successfully."
  },
  "to" : "Unique Key"
}

在 android 中使用 Firebase 向所有设备发送推送通知的 JSON 结构是什么?

最佳答案

我有同样的需求,我通过将 to 设置为 /topics/all 并将 restricted_pa​​ckage_name 设置为我的包名称来解决它:

{
    "to": "/topics/all",
    "restricted_package_name": "<PACKAGE_NAME>",
    "notification": {
        "title": "<TITLE>",
        "body": "<BODY>",
        "click_action": "FCM_PLUGIN_ACTIVITY"
    }
}

我发送的每条消息都由移动应用程序接收,无需以编程方式订阅主题。

关于android - 使用 Firebase 向所有已注册设备发送推送通知的 JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39690293/

相关文章:

java - Android:从 Intent 中获取 App-Name

firebase - 如何解决flutter中的内部错误以使用firebase_auth

android - 如何使用 firebase (android) 搜索正则表达式?

android - android中的两个推送通知服务

android - 微调器从顶部而不是底部打开

java - ExpandableListView 中的静态子项

android - 通过本地网络在 Genymotion 上运行应用程序

android - 在 Firebase 中获取 child 的名字

jquery - 如何为跨平台Web应用程序实现推送通知服务?

android - 注册 ID 更改后处理 GCM 中存储的消息