首先自定义
MyReceiver 继承 BroadcastReceiver
在
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
Logger.d(TAG, "[MyReceiver] 用户点击打开了通知");
//打开自定义的Activity
Intent i = new Intent(context, TestActivity.class);
i.putExtras(bundle);
//i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP );
context.startActivity(i);
}
如此即可在点击通知栏后跳转到指定activity
在里面接收bundle
Bundle bundle = getIntent().getExtras();
String title = null;
String content = null;
if(bundle!=null){
title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
// content = bundle.getString(JPushInterface.EXTRA_ALERT);
content = bundle.getString(JPushInterface.EXTRA_EXTRA);//"extras"
}
tv.setText("Title : " + title + " " + "Content : " + content);
EXTRA_EXTRA 这个是极光定义的自定义json (里面的数据我后台可以自由发挥)
参数中间的json就是我们自定义的部分
手机端获取到的值 第一个为正常获取的message 第二个为自定义数据