【问题标题】:Firebase Cloud Message Sending Notification through phoneFirebase 云消息通过电话发送通知
【发布时间】:2018-01-18 15:12:01
【问题描述】:

我想出了如何使用 Firebase Cloud Messaging 发送和接收 Firebase 推送通知

我想知道如何使用 android studio 中的代码手动发送通知,以便我可以从任何手机发送。

【问题讨论】:

  • 你可以使用firebase函数见例子github.com/firebase/functions-samples/tree/master/…
  • 在使用 FCM 时,强烈建议不要从客户端设备发送消息。这是因为您必须将 Server Key 存储在客户端,这不是正确的使用方法,并且可能会被未经授权的用户暴露和利用。

标签: android firebase firebase-cloud-messaging


【解决方案1】:

您使用 FCM 从手机发送消息。您需要使用要发送的有效负载和在 Firebase 控制台项目中找到的服务器密钥创建一个 POST 到 https://fcm.googleapis.com/fcm/send api。

作为使用to 参数向单个用户发送有效负载的示例:

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

另外,to 参数可用于主题"to": "topics/yourTopic"

在data 中,您可以发送任何您想要的内容,消息会在来自 Firebase 的onMessageReceived() 服务中接收。

您可以在 Firebase documentation 中找到更多详细信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-02
    • 2016-12-08
    • 1970-01-01
    • 1970-01-01
    • 2017-10-04
    • 1970-01-01
    相关资源
    最近更新 更多