最近需要极光推送,不知道如何获取到协议传过来的值,
推送类型:透传消息
消息内容:{"cmd":"force_logout","token":"被挤掉的用户令牌","msg":"具体提示信息"}
应该怎么获取,在receiver中应该怎么写???
3条回答 默认 最新
- XuZhenhao0609 2016-12-04 03:35关注
激光推送的SDK里面有一个simple,在MyReceiver里面这样去拿
String content = (String) bundle.get(JPushInterface.EXTRA_ALERT);就能拿到内容,看你的需求是要解析一个json数据,demo里面也有。
DEMO的71行里面基本把解析方法已经说出来了
// 打印所有的 intent extra 数据
private static String printBundle(Bundle bundle) {
StringBuilder sb = new StringBuilder();
for (String key : bundle.keySet()) {
if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
sb.append("\nkey:" + key + ", value:" + bundle.getInt(key));
}else if(key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)){
sb.append("\nkey:" + key + ", value:" + bundle.getBoolean(key));
} else if (key.equals(JPushInterface.EXTRA_EXTRA)) {
if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) {
Log.i(TAG, "This message has no Extra data");
continue;
}try { JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA)); Iterator<String> it = json.keys(); while (it.hasNext()) { String myKey = it.next().toString(); sb.append("\nkey:" + key + ", value: [" + myKey + " - " +json.optString(myKey) + "]"); } } catch (JSONException e) { Log.e(TAG, "Get message extra JSON error!"); } } else { sb.append("\nkey:" + key + ", value:" + bundle.getString(key)); } } return sb.toString(); }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报