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, Setset) { LogHelp.i("JPush","Login:"); } });
2.需求:退出登录就无法接收推送通知
//极光推送解除绑定别名JPushInterface.stopPush(getActivity());//停止推送JPushInterface.setAlias(getActivity(), "", new TagAliasCallback() { @Override public void gotResult(int i, String s, Setset) { 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是否为activityif(!(context instanceof Activity)){ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);}context.startActivity(intent);