简体   繁体   English

应用程序在 android 中终止时未收到通知

[英]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.

相关问题 如何在Android聊天应用程序处于后台时接收消息作为通知 - How to receive message as notification when the android chat application is in background 我如何仅在应用程序终止时接收 FCM 通知,如果应用程序在后台运行则不接收它 - How I can receive FCM notification only when app is terminated and doesn't receive it if app is working in background 应用程序未运行时小米没有收到通知 - Xiaomi does not receive notification when application is not running Android服务在音量变化时接收通知 - Android service to receive notification when volume changes 收到文件时在Android上发出通知 - notification on android when you receive a file Android | 针对您的应用程序运行测试时是否可能收到推送通知 - Android | Is it possible to receive a push notification when running test against your application Delphi Android Firebase 云消息:收到通知时应用程序崩溃 - Delphi Android Firebase Cloud Messaging : Application crashes on notification receive 如何接收有关Android已杀死我的应用程序的通知? - How to receive notification that android has killed my application? 在我的应用程序中收到有关Android热关机的通知 - Receive notification of Android's thermal shutdown in my application Android-如果应用程序终止,则远程服务也会终止 - Android - Remote service is terminated if application is terminated
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM