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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog