gpt4 book ai didi

java - 通过 FCM onMessageReceived 方法从 RemoteMessage 获取值

转载 作者:IT老高 更新时间:2023-10-28 20:36:41 26 4
gpt4 key购买 nike

我已将 gcm 迁移到 fcm 以获取推送通知消息。但是我如何从收到的 RemoteMessage 中获取 bundle 数据的 onMesssageReceived 方法。

Old GCM give bundle data onMessageReceiced method but in FCM there is RemoteMessage data.

所以请告诉我如何解析远程消息以获取通知的所有值。

我的工资单

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

最佳答案

这是几乎不言自明的代码 fragment 。

你以Map的形式获取数据

public void onMessageReceived(RemoteMessage remoteMessage)
{
Log.e("dataChat",remoteMessage.getData().toString());
try
{
Map<String, String> params = remoteMessage.getData();
JSONObject object = new JSONObject(params);
Log.e("JSON_OBJECT", object.toString());
}
}

确保从服务器发送的数据格式正确,即在“数据”键中

这里是演示 Json 文件

{
"to": "registration_ids",
"data": {
"key": "value",
"key": "value",
"key": "value",
"key": "value"
}
}

关于java - 通过 FCM onMessageReceived 方法从 RemoteMessage 获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38244332/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com