We are working on notification trampolines on Android 12. Originally our app launches an activity by a broadcast receiver.
I found out that using PendingIntent.getActivity
instead of PendingIntent.getBroadcast
would solve the problem.
Regarding this, I have a following concern.
When the broadcast receiver is used, i.e. when PendingIntent.getBroadcast
is used, I programmed so that the broadcast receiver determines whether to launch the app.
However, I no longer use the broadcast receiver due to notification trampolines. Therefore, PendingIntent.getActivity
launches the app without choice.
I would like to know if there is any way to determine whether to launch the app depending of the state of app without using the broadcast receiver.
For example;
- when App is in state A:Launch the app with a push notification tap
- when App is in state B:NOT launch the app with a push notification tap
CodePudding user response:
sort of workaround would be to launch some dedicated Activity
, which may be set as fully transparent without any enter/exit animation, noHistory
flag etc. and in there you may run your checking logic - starting "real" Activity
or just finish()
if there is no need
CodePudding user response:
I'm using a transparent activity to handle this issue. all the notification related works are handled in the transparent activity.
Intent intent = new Intent(mContext, NotificationActivity.class);
intent.putExtra("notification", parseInt(this.mActionDetail.getNotifyId()));
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
builder.setContentIntent(pendingIntent);
builder.setAutoCancel(true);
notificationManager.notify(parseInt(this.mActionDetail.getNotifyId()), builder.build());
create a transparent activity NotificationActivity.class then you can identify the application state then you can decide the action