参见英文答案 >
Android app not receiving Firebase Notification when app is stopped from multi-task tray 6个
我正在尝试熟悉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
> Content-Type – application / json
要获取服务器密钥,可以在firebase控制台中找到它:您的项目 – >设置 – >项目设置 – >云消息传递 – >服务器密钥