qq_34025020 2016-12-03 04:53 采纳率: 0%
浏览 4455
已采纳

Android 极光推送如何获取到推送过来的消息???

最近需要极光推送,不知道如何获取到协议传过来的值,
推送类型:透传消息
消息内容:{"cmd":"force_logout","token":"被挤掉的用户令牌","msg":"具体提示信息"}
应该怎么获取,在receiver中应该怎么写???

  • 写回答

3条回答 默认 最新

  • XuZhenhao0609 2016-12-04 11: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();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献