FCM background/not running notification getIntent(

2019-08-16 05:21发布

I'm working on an app in which i get from the server some push notifications when some events are triggered.

When the application is in foreground all works great, in the onMessageReceived() i get the remoteMessage and handle it based on its map key value.

The problem is in background or when the application is not running...I still get the notification in the device screen, and when i tap on it the activity starts.

I do the following verification after the activity starts:

 Bundle mBundle = getIntent().getExtras();
    if(mBundle != null)
    {
    //do stuff
    }

But i always get the mMap = null in the bundle object which means i cannot handle properly the push notification.

enter image description here

Can something be done about this ?

1条回答
我命由我不由天
2楼-- · 2019-08-16 05:59

There are two types of Notification Message

1. Notification message

Notification Message can be fetched when application is running, but if the application is not running(killed) then it will not work. It only shows that notification is arrived.

example,

{
  "message":{
    "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification":{
      "title":"Portugal vs. Denmark",
      "body":"great match!"
    }
  }
}

2. Data message (also known as silent notification)

Whereas Data Messagegs works even if the application is not running.

example,

{
  "message":{
    "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "data":{
      "Nick" : "Mario",
      "body" : "great match!",
      "Room" : "PortugalVSDenmark"
    }
  }
}
查看更多
登录 后发表回答