簡體   English   中英

應用程序在 android 中終止時未收到通知

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM