我已经迁移 gcm to fcm
用于推送通知消息。但是我如何从 RemoteMessage 获取捆绑数据收到 onMesssageReceived 方法。
Old GCM give bundle data onMessageReceiced method but in FCM there is RemoteMessage data.
所以请告诉我如何解析 remotemessage 以获得通知的所有价值。
我的工资单
{
"collapse_key":"score_update",
"priority":"high",
"content_available":true,
"time_to_live":108,
"delay_while_idle":true,
"data":
{
"message": "Message for new task",
"time": "6/27/2016 5:24:28 PM"
},
"notification": {
"sound": "simpleSound.wav",
"badge": "6",
"title": "Test app",
"icon": "myicon",
"body": "hello 6 app",
"notification_id" : "1140",
"notification_type" : 1,
"notification_message" : "TEST MESSAGE",
"notification_title" : "APP"
},
"registration_ids": ["cRz9SJ-gGuo:APA91bFJPX7_d07AR7zY6m9khQro81GmSX-7iXPUaHqqcOT0xNTVsOZ4M1aPtoVloLNq71-aWrMCpIDmX4NhMeDIc08txi6Vc1mht56MItuVDdA4VWrnN2iDwCE8k69-V8eUVeK5ISer"
]
}
原文由 Jatinkumar Patel 发布,翻译遵循 CC BY-SA 4.0 许可协议
在 FCM 中,您收到的是 RemoteMessage 而不是 Bundle。
下面是我在我的应用程序中使用的方式,其中数据是我的 RemoteMessage
以下是我从服务器发送的通知数据
因此,您必须根据您的回复解析每个字段。当我调试代码时,您将在 RemoteMessage 中收到映射并将这些字段转换为适当的数据类型,因为所有这些数据都以字符串形式出现。