![](/img/trans.png)
[英]How to receive message as notification when the android chat application is in background
[英]Notification not receive when Application terminated in android
我使用 firebase 将通知推送到设备令牌。 当应用程序打开或在前台时,我可以很好地收到通知。 但是当应用程序在当前任务中被杀死或清除应用程序时,我无法收到通知发送。
我在第一次工作时就尝试过 onMessageReceived 。 但现在它在杀死应用程序时不起作用。
代码接收通知:
class MyFirebaseMessagingService: FirebaseMessagingService() { override fun onMessageReceived(p0: RemoteMessage) { val data = p0..:data Log,e("AAAAAAAAAAAAA: ","data 111111111111111111111111111111111111111111111111:" + data["key1"]) } }
发布发送通知数据:发送至: https://fcm.googleapis.com/fcm/send
数据:
{ "to": "token key", "data": { "key1": "value1", "key2": "value2", "other_key": true } }
结果,应用程序正在打开,我可以很好地接收数据,但是当我被杀死时我无法接收数据。
如果您将数据发送到https://fcm.googleapis.com/fcm/send您使用的是旧版 http 协议,如您在此处看到的
这在文档中不是很清楚。
在此协议中,当应用程序处于后台或关闭时接收数据消息,您应该使用此有效负载:
{
"to" : "token key",
"data": {
"key1" : "value1",
"key2" : "value2",
"other_key" : true
},
"priority" : 10,
"time_to_live" : 60
}
首先以最高优先级 (10) 进行测试,然后根据您的需要降级。 还可以根据您的需要以秒为单位调整 time_to_live。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.