简体   繁体   English

Android Firebase 后台未收到推送通知?

[英]Android Firebase Push notification not received in background?

I am getting push notification via onMessageReceived(Remotemessage mesg) when my app is open state.当我的应用程序打开 state 时,我通过 onMessageReceived(Remotemessage mesg) 收到推送通知。 If my app is in killed state i am getting push notification but not from onMessageReceived().如果我的应用程序被杀死 state 我收到推送通知,但不是来自 onMessageReceived()。

means, after push notification received, based on the data from the notification i need to redirect the page, when notification tapped.意味着,在收到推送通知后,根据通知中的数据,当点击通知时,我需要重定向页面。 if app in foreground that works fine.如果前台的应用程序运行良好。 When i killed, i got notification on tray but when i tap on the notification it opens my app only not that redirected page.当我杀死时,我在托盘上收到通知,但是当我点击通知时,它只会打开我的应用程序,而不是那个重定向页面。 I put log and checked that, onMessageReceived is not even called.我放了日志并检查了一下,甚至没有调用 onMessageReceived 。 But got notification on tray.但在托盘上收到通知。 I searched a lot and lot.我搜索了很多很多。 Couldn't find the issue.找不到问题。 Backend payload is below后端有效负载如下

  "to": "f2dFWIn81FY:APA91bGumzp0LRr4hvGqUb9WMOvmWqvHSqYcCBzTJlbJs2dmpfrv_tAdu",
  "priority": "high",
  "content_available": true,
  "Type": "Order",
  "notification": {
     "body": "Your [2224531] order is rejected",
     "title": "Order",
     "sound": "default"
  },
  "data": {
     "Title": "Your [2224531] order is rejected",
     "NotificationId": "efb46a45-cd9c-4cf7-881f-9510c24555a6"
  }
}

I am trying to get the data in MainActivity.java but the bundle is null!!我正在尝试获取 MainActivity.java 中的数据,但捆绑包为空!!

Image of MainActivity MainActivity 的图像

This is working as intended.这是按预期工作的。 onMessageReceived is not called if app is in the background/closed.如果应用程序处于后台/关闭状态,则不会调用onMessageReceived The data specified within the message should be available like this:消息中指定的数据应该像这样可用:

if (intent?.hasExtra("NotificationId") == true) {
    val id = intent?.extras?.getString("NotificationId")?.toString())                    
}

In your onCreate startup activity if the app was opened from the message click intent.如果应用程序是从消息单击意图打开的,则在您的onCreate启动活动中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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