<分区>
我正在尝试熟悉 Firebase 通知。它工作正常,但当应用程序未打开时,我无法从通知控制台接收消息。
我知道文档说:
if your app in foreground or background you can receive message in onMessageReceived method, otherwise user will receive notification in tray... click on it will open main activity with data inside intent
但有没有什么方法可以在应用程序关闭的情况下从通知控制台捕获每条消息?
==== 回答 ====
寻找答案 here
无法从通知控制台发送数据消息。
但是还有其他方法可以向设备发送通知,它们将被捕获在 onMessageReceived 中!
您可以使用终端(Mac 或 Linux)或像 Postman 这样的服务在这个链接上发送 Post 请求:https://fcm.googleapis.com/fcm/send
与下一个主体:
{
"to": "/topics/your_topic_here",
"data": {
"text":"text",
"text1":"text1",
...
}
}
您还需要添加 2 个标题:
- 授权 - key=your_server_key_here
- 内容类型 - application/json
要获取您的服务器 key ,您可以在 firebase 控制台中找到它:您的项目 -> 设置 -> 项目设置 -> 云消息传递 -> 服务器 key