0

服务器向我发送通知中的数据,如下所示:

{    "to" : "xxxxxxxxxx",  
     "notification": 
       {
         "badge": "1",
         "bodyLocArgs": "['XXXX']",
         "bodyLocKey": "AAA.BBB.CCC",
         "image": "url_image",
         "sound": "default"
       },
    "data": {
        "friend": "5dde6ffe47f65624004556d1",
        "type": "FRA"
    } }

在我的函数中,onMessageReceived我无法获取对象的值"notification",我尝试过,remoteMessage.getNotification().getBody()但它总是给我nullremoteMessage.getData()因为我发现只有"data"“朋友”和“类型”的对象,所以我的问题是如何获取对象"notification"

在此处输入图像描述

4

2 回答 2

0

通知没有正文或标题。所以 .getBody() 总是空的。

你可以这样使用:

String bodyLocKey = remoteMessage.getNotification().getBodyLocalizationKey();
String [] bodyLocArgs = remoteMessage.getNotification().getBodyLocalizationArgs();

 remoteMessage.getNotification().getBody(); // null
 remoteMessage.getNotification().getTitle(); // null

更多方法

于 2020-04-20T21:14:03.623 回答
0

发送这种格式的通知对我来说非常有用,在后台、前台和已终止的应用程序中,问题出在子“通知”中

{    "to" : "xxxxxxxxxx",  

    "data": {
         "badge": "1",
         "bodyLocArgs": "['XXXX']",
         "bodyLocKey": "AAA.BBB.CCC",
         "image": "url_image",
         "sound": "default"
         "friend": "5dde6ffe47f65624004556d1",
         "type": "FRA"
    } }

remotemessage.getData()我找到了我所有的通知值。

于 2020-04-23T20:41:10.800 回答