Get value from RemoteMessage from FCM onMessageReceived method(通过 FCM onMessageReceived 方法从 RemoteMessage 获取值)
问题描述
我已将 gcm 迁移到 fcm
以获取推送通知消息.但是我如何从收到的 RemoteMessage 中获取捆绑数据的 onMesssageReceived 方法.
I have migrate gcm to fcm
for push notification message.
but how I Get bundle data from RemoteMessage received onMesssageReceived method.
Old GCM give bundle data onMessageReceiced method but in FCM there is RemoteMessage data.
所以请告诉我如何解析远程消息以获取通知的所有值.
So please tell me how I parse remotemessage for get all value of notification.
我的工资单
{
"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"
]
}
推荐答案
在 FCM 中你收到的是 RemoteMessage 而不是 Bundle.
In FCM you received RemoteMessage instead of Bundle.
以下是我在应用程序中使用的方式,其中数据是我的 RemoteMessage
Below is the way I used in my application where data is my RemoteMessage
Map<String, String> data = remoteMessage.getData()
int questionId = Integer.parseInt(data.get("questionId").toString());
String questionTitle = data.get("questionTitle").toString();
String userDisplayName = data.get("userDisplayName").toString();
String commentText = data.get("latestComment").toString();
以下是我从服务器发送的通知数据
Below is my notification data which I am sending it from server
{
"registration_ids": "",
"data": {
"questionId": 1,
"userDisplayName": "Test",
"questionTitle": "Test",
"latestComment": "Test"
}
}
因此,您必须根据您的回复解析每个字段.由于我已经调试了代码,您将在 RemoteMessage 中收到地图,并将这些字段转换为适当的数据类型,因为所有这些数据都以字符串形式出现.
So you have to parse each and every field as per your response. As I have debugged the code you will receive map in your RemoteMessage and cast those fields in appropriate data types as all those data comes as string.
这篇关于通过 FCM onMessageReceived 方法从 RemoteMessage 获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通过 FCM onMessageReceived 方法从 RemoteMessage 获取值


- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01