使用了ARouter模块化开发的应用,做消息通知notification应该如何设置PendingIntent参数?

notification中通过设置点击通知打开指定的activity。

原本使用的是通过setContentIntent(pendingIntent)来是想上述效果。其中pendingIntent = PendingIntent.getActivity(context,requestCode,intent,flags)。但是现在改成模块化开发了,这里的intent肯定就不能用了。

那么在模块化开发中想要实现如上述点击通知跳转至指定页面应该如何设置实现?

https://blog.csdn.net/wu996489865/article/details/73992243

可以使用PendingIntent.getBroadcast用广播来监听跳转

以下是关键代码:

  Intent intent = new Intent(applicationContext, NotificationBroadcastReceiver.class);
  intent.setAction("notification_jumped");
  intent.putExtra("Data", new Gson().toJson(data));
  intent.putExtra(NotificationBroadcastReceiver.TYPE, NotificationCode);
  PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 123, intent, PendingIntent.FLAG_UPDATE_CURRENT);

我data格式是ARouter的path+页面初始化所需的参数

然后在notification.Builder的

setContentIntent(pendingIntent)

就实现了与notification的绑定,再在自己定义的广播NotificationBroadcastReceiver里重新

onReceive方法以及写一些逻辑即可,如动作未notification_jumped时取Data里的path和参数进行跳转