900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > android收到极光推送跳转 极光推送 在跳转Activity获取自定义数据

android收到极光推送跳转 极光推送 在跳转Activity获取自定义数据

时间:2024-04-17 13:21:37

相关推荐

android收到极光推送跳转 极光推送 在跳转Activity获取自定义数据

首先自定义

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 第二个为自定义数据

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。