FCM background/not running notification getIntent().getExtra() has mMap allways null

↘锁芯ラ 提交于 2019-12-13 03:57:13

问题


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.

Can something be done about this ?


回答1:


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"
    }
  }
}


来源:https://stackoverflow.com/questions/49152527/fcm-background-not-running-notification-getintent-getextra-has-mmap-allways

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!