canceling notification after clicking on notification builder action button
C

1

0

Starting from android 12 , starting activity from BroadcastReceiver and services is not possible anymore, according to the documentation this is called Notification trampoline restrictions and now we should use pendingintent that take us directly to the activity concerned, the issue here is that i am used to dismiss the notification in the broadcastreceiver

private class NotificationBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {

NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

final int NOTIFICATION_ID = intent.getIntExtra("notificationId",0);

Log.v("NOTIFICATION_ID",Integer.toString(NOTIFICATION_ID));

mNotificationManager.cancel(NOTIFICATION_ID);

but now i don't have where to cancel notification without the broadcastReceiver....after clicing the actionButton that added to my notificationBuilder, the notification is not dismissed and still going , anyway to manage that ?

Conventual answered 23/7 at 13:41 Comment(0)
T
0

The PendingIntent to launch your Intent can be used to cancel the Notification. Just add the NotificationId to the Intent you use to launch the Activity and the Activity can cancel the Notification in either onCreate() or onNewIntent().

Or, depending on your application requirements and architecture, you can just cancel all Notifications in the Activity, using cancelAll().

Tepid answered 24/7 at 16:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.