【发布时间】:2017-11-03 19:19:34
【问题描述】:
我正在处理 FCM 消息,我有以下功能:
public void onMessageReceived(final RemoteMessage remoteMessage)
{
final Map<String, String> data = remoteMessage.getData();
//...
}
出于测试目的,我有一个包含数据的 Json 文件,我想将该 Json 文件从我的测试方法发送到 onMessagereceived() 。因此,我需要使用 Json 文件初始化 RemoteMessage 对象,并将此 RemoteMessage 对象传递给函数。如何初始化它?
我的 JSON 文件:
{
"data": {
"id" : "4422",
"type" : "1",
"imageUrl" : "https://image.freepik.com/free-vector/android-boot-logo_634639.jpg",
"smallTitle" : "DoJMA v2",
"smallSubTitle" : "Update now from Google Play Store",
"ticker" : "New update for DoJMA",
"contentInfo" : "",
"link" : "https://photo2.tinhte.vn/data/avatars/l/1885/1885712.jpg?1402763583",
"className" : "HomeActivity",
"page" : "2",
"bigTitle" : "DoJMA Android app version 2 released!",
"bigSubTitle" : "Hi folks! New DoJMA update is here! Major redesigning and improvements! This app was made by the Mobile App Club.They work really hard man...and get good products",
"bigSummaryText" : "Update now"
},
"registration_ids": ["dQYmpLUACXQ:APA91bGl-NoIMJ2_DcctF5-OA8ghyWuyrMfsz3uhlj1BySl6axkAsmv5y_7YGfpQQJ2E0lP_fTcxpHpZdkJzY1tbcWA36e78ooxC_b0a1PAank9gFIAUHVZkHKmZT70MPZosCgvRlVfq","dfLXnRI36qY:APA91bFyjLblijVIjGLCGWVeB1B0z5j_3TYqRytJ-8hvuUESpDlX59gWF3hU-I-kA4VrRCPpEVFWl18ZarnPjqxxtZgFkVxoLr77HRex27VN7Mh3xupWykmKq_nnVIlVzrODKwKI7ktM"]
}
【问题讨论】:
-
在 JSONObject 中传递你的数据 json = new JSONObject("Your json String"); onMessageReceived 方法内部。
-
@Janak 但如何将其转换为 remoteMessage 对象?
-
你想要这个 Json 在你的响应中?
-
@Janak 我想将此 Json 传递给
onMessageReceived(),因此我必须将其转换为RemoteMessage对象。我的问题是如何做到这一点。
标签: android json firebase firebase-cloud-messaging