Android - Remove action button from notification
I am using following workaround:
NotificationCompat.Builder builder = //existing instance of builder
//...
try {
//Use reflection clean up old actions
Field f = builder.getClass().getDeclaredField("mActions");
f.setAccessible(true);
f.set(builder, new ArrayList<NotificationCompat.Action>());
} catch (NoSuchFieldException e) {
// no field
} catch (IllegalAccessException e) {
// wrong types
}
from here: https://code.google.com/p/android/issues/detail?id=68063
Note:
Proguard may break the button clearing in obfuscated build. Fix is to add the following two lines in proguard-rules.pro
-keep class androidx.core.app.NotificationCompat { *; }
-keep class androidx.core.app.NotificationCompat$* { *; }
I had the same problem and found a solution for this. I created another builder and added two "empty" actions like this:
builder.addAction(0, null, null);
builder.addAction(0, null, null);
(one for each button I had, so if you have three, call it three times).
Then when calling Notify, it removes the buttons.
If you are using the NotificationCompat.Builder from the v4 Support Library, you can simply access the builder's action collection directly (Unfortunately no public mutators are provided).
The following will do the trick (Of course you must update re-notify):
NotificationCompat.Builder notifBuilder = NotificationCompat.Builder(context);
...
notifBuilder.mActions.clear();