0
votes

I am getting push notification via onMessageReceived(Remotemessage mesg) when my app is open state. If my app is in killed state i am getting push notification but not from 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. 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!!

Image of MainActivity

1

1 Answers

0
votes

This is working as intended. onMessageReceived is not called if app is in the background/closed. 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.