[英]Notification not receive when Application terminated in android
I use firebase push notification to device token.我使用 firebase 将通知推送到设备令牌。 When app is opening or in foreground I can get notification well.当应用程序打开或在前台时,我可以很好地收到通知。 But when app is kill or clear app on current task, I cannot receive notification send.但是当应用程序在当前任务中被杀死或清除应用程序时,我无法收到通知发送。
I have tried on onMessageReceived aleardy at first time work.我在第一次工作时就尝试过 onMessageReceived 。 but now it's not work when killed app.但现在它在杀死应用程序时不起作用。
Code Receive Notification:代码接收通知:
class MyFirebaseMessagingService: FirebaseMessagingService() { override fun onMessageReceived(p0: RemoteMessage) { val data = p0..:data Log,e("AAAAAAAAAAAAA: ","data 111111111111111111111111111111111111111111111111:" + data["key1"]) } }
Post Send notification data: Send to: https://fcm.googleapis.com/fcm/send发布发送通知数据:发送至: https://fcm.googleapis.com/fcm/send
Data:数据:
{ "to": "token key", "data": { "key1": "value1", "key2": "value2", "other_key": true } }
Result, for app is opening, I can receive data well, but when killed I cannot receive data.结果,应用程序正在打开,我可以很好地接收数据,但是当我被杀死时我无法接收数据。
If you're sending data to https://fcm.googleapis.com/fcm/send you're using the legacy http protocol as you can see here如果您将数据发送到https://fcm.googleapis.com/fcm/send您使用的是旧版 http 协议,如您在此处看到的
This is not very clear in documentation.这在文档中不是很清楚。
In this protocol to receive the data message when app is in background or closed you should use this payload:在此协议中,当应用程序处于后台或关闭时接收数据消息,您应该使用此有效负载:
{
"to" : "token key",
"data": {
"key1" : "value1",
"key2" : "value2",
"other_key" : true
},
"priority" : 10,
"time_to_live" : 60
}
Test first with maximum priority (10) and then downgrade according t your needs.首先以最高优先级 (10) 进行测试,然后根据您的需要降级。 Also adjust time_to_live in seconds according to your needs.还可以根据您的需要以秒为单位调整 time_to_live。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.