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 获取值


基础教程推荐
- 从 python 访问 JVM 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01