FCM后台/未运行通知getIntent().getExtra()的mMap始终为null [英] FCM background/not running notification getIntent().getExtra() has mMap allways null

查看:108
本文介绍了FCM后台/未运行通知getIntent().getExtra()的mMap始终为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,在该应用程序中,当某些事件被触发时,我会从服务器获得一些推送通知.

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

当应用程序在前台运行时,一切都很好,在onMessageReceived()中,我获取了remoteMessage并根据其映射键值对其进行处理.

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
    }

但是我总是在bundle对象中得到mMap = null,这意味着我无法正确处理推送通知.

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.通知消息

可以在应用程序运行时获取通知消息,但是如果应用程序未运行(已终止),则它将无法正常工作.它仅显示通知已到达.

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.

示例,

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

2.数据消息(也称为静默通知)

即使应用程序未运行,数据消息也可以正常工作.

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

示例,

{
  "message":{
    "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "data":{
      "Nick" : "Mario",
      "body" : "great match!",
      "Room" : "PortugalVSDenmark"
    }
  }
}

这篇关于FCM后台/未运行通知getIntent().getExtra()的mMap始终为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆