zoukankan      html  css  js  c++  java
  • 极光推送发送控制/别名/取值

     1.需求:登录以后才能接收推送通知

    //极光推送绑定别名
    JPushInterface.init(LoginActivity.this);             // 初始化 JPush
    LogHelp.i("JPush","isPushStopped:"+JPushInterface.isPushStopped(LoginActivity.this));
    if(JPushInterface.isPushStopped(LoginActivity.this)){
        JPushInterface.resumePush(LoginActivity.this);//恢复极光推送
    }
    LogHelp.i("JPush","JPushAlias:"+Constant.JPushAlias+response.body().getData().getUserId());
    JPushInterface.setAlias(LoginActivity.this, Constant.JPushAlias+response.body().getData().getUserId() , new TagAliasCallback() {
        @Override
        public void gotResult(int i, String s, Set<String> set) {
                LogHelp.i("JPush","Login:");
        }
    });

    2.需求:退出登录就无法接收推送通知

    //极光推送解除绑定别名
    JPushInterface.stopPush(getActivity());//停止推送
    JPushInterface.setAlias(getActivity(), "", new TagAliasCallback() {
        @Override
        public void gotResult(int i, String s, Set<String> set) {
            LogHelp.i("JPush","Logout");
        }
    });

    3.需求:获取通知栏里面的值

    //标题
    String title = bundle.getString(JPushInterface.EXTRA_TITLE);
    //消息
    String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
    //附加字段--得到的是json字符串,然后解析
    String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);

    4.点击通知栏因为拿不到ancivity的对象,所以需要判断,且启动模式为new instance

    //如果是点击通知栏跳转需要判断context是否为activity
    if(!(context instanceof Activity)){
          intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }
    context.startActivity(intent);

    欢迎关注我的微信公众号:安卓圈

  • 相关阅读:
    python之递归函数
    python之内置函数
    python之迭代器与生成器
    python之装饰器函数
    python之函数进阶
    python之初识函数
    一起学Android之Dialog
    一起学Android之Menu
    一起学Android之GridView
    一起学Android之ViewPager
  • 原文地址:https://www.cnblogs.com/anni-qianqian/p/5784446.html
Copyright © 2011-2022 走看看