I have a notification that I'm trying to update by reusing the same Notification Builder, but there's no way to clear the buttons, you can only call addAction
. Not using the same Builder results in the notification flashing, which is undesirable. Are there any solutions to this? I'm using NotificationCompat
from the v4 support library.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Step 3 − Add the following code to src/MainActivity.
First build a Notification putExtra("action","actionName"); pIntentlogin = PendingIntent. getBroadcast(context,1,intentAction,PendingIntent. FLAG_UPDATE_CURRENT); drivingNotifBldr = (NotificationCompat. Builder) new NotificationCompat.
notificationBuilder.mActions.clear();
It's actually public ArrayList<Action>
, so you can do whataver you want with it.
You have two options to achieve that:
remoteView.setViewVisibility(...)
for example... Or change the text of the buttons...Use reflection to clear the builders actions. Would work like following:
try {
//Use reflection to remove all old actions
Field f = mNotificationBuilder.getClass().getDeclaredField("mActions");
f.setAccessible(true);
f.set(mNotificationBuilder, new ArrayList<>());
}
catch (NoSuchFieldException e) {}
catch (IllegalAccessException e) {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With