我正在接收来自C#应用程序的推送,响应如下所示(它是一个包):
componentDidUpdate
我如何获得警报的标题和正文?
我已经尝试了 Bundle [
{
google.sent_time=1472471614026,
gcm.notification.msgid=27,
google.message_id=0:1472471614038882%8e7302d58e7302d5,
gcm.notification.aps=
{
"badge":1,
"alert":
{
"action-loc-key":"alert action key",
"title":"The alert title",
"body":"The alert body"
}
},
collapse_key=com.devise.push
}
]
答案 0 :(得分:-1)
是的,你已经尝试了
bundle.getString("gcm.notification.aps");
这是correnct会给你完整的json字符串所以你只需要像这样解析json
String res =bundle.getString("gcm.notification.aps");
try {
JSONObject mJSONObject = new JSONObject(res);
String title =mJSONObject.getJSONObject("alert").getString("title");
String action =mJSONObject.getJSONObject("alert").getString("action-loc-key");
String body =mJSONObject.getJSONObject("alert").getString("body");
Log.e(TAG, "MSG: " + title+ " :: " + action + " :: " + body );
}catch (JSONException e){
e.printStackTrace();
}