问题描述
我已将 gcm迁移至fcm
,以取得推送通知讯息。
,但我如何从RemoteMessage接收onMesssageReceived方法的bundle数据。
旧GCM给bundle数据onMessageReceiced方法,但在FCM中有RemoteMessage数据。
所以请告诉我如何解析remotemessage以获取所有通知值。
MY PAYROL
{
collapse_key:score_update,
priority:high,
content_available:true,
time_to_live:108,
delay_while_idle:true,
data:
$ bmessage:消息为新任务,
time:2016/6/27 5:24:28
},
通知:{
sound:simpleSound.wav,
badge:6,
title:测试应用程序,
icon :myicon,
body:hello 6 app,
notification_id:1140,
notification_type:1,
notification_message:测试消息,
的notification_title: APP
},
的registration_ids:[ cRz9SJ-gGuo:APA91bFJPX7_d07AR7zY6m9khQro81GmSX-7iXPUaHqqcOT0xNTVsOZ4M1aPtoVloLNq71-aWrMCpIDmX4NhMeDIc08txi6Vc1mht56MItuVDdA4VWrnN2iDwCE8k69-V8eUVeK5ISer
]
}
以下是我在我的应用程序中使用的方式,其中数据是我的RemoteMessage
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();
以下是我通过服务器发送的通知数据
{
registration_ids:,
data:{
questionId:1,
userDisplayName:Test,
questionTitle:Test,
latestComment:Test
}
}
所以你必须根据你的回答解析每一个领域。
因为我调试了代码,您将在RemoteMessage中接收映射,并将这些字段转换为适当的数据类型,因为所有这些数据都以字符串形式出现。
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.
MY PAYROL
{
"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"
]
}
In FCM you received RemoteMessage instead of Bundle.
Below is the way I used in my application where data is my RemoteMessage
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"
}
}
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的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!