简体   繁体   中英

Notification not receive when Application terminated in android

I use firebase push notification to device token. 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. 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

  • 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

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. Also adjust time_to_live in seconds according to your needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM