I'm trying to show the X on the MediaStyle
Notification
Android P. I see a lot of posts basically saying this won't work on API 21 and higher I think but here is screenshot of an app showing it:
I've tried this code below but it doesn't show it:
Notification notification = new NotificationCompat.Builder(getApplicationContext(), TESTID)
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle("Track title")
.setContentText("Artist - Album")
.addAction(R.drawable.ic_fast_forward_black_24dp, "fwd", pi)
.addAction(R.drawable.ic_fast_forward_black_24dp, "fwd", pi)
.addAction(R.drawable.ic_fast_forward_black_24dp, "fwd", pi)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.vectors_525058875))
.setAutoCancel(false)
.setStyle(new MediaStyle()
.setMediaSession(mediaSessionCompat.getSessionToken()).setShowCancelButton(true).setCancelButtonIntent(pi))
.build();
notificationManager.notify(300, notification);
You must use very little known class DecoratedMediaCustomViewStyle that is similar to MediaStyle except that it let you customize what you display into the content area using a RemoteViews. The trick is to replicate the MediaStyle layout (you can copy it from the support lib) and customize it, adding an X button for example.
However, there are 2 caveats:
Update 2020: DecoratedMediaCustomViewStyle makes MIUI 12 Crash in SystemUI. MIUI is mostly found on Xiaomi/Redmi devices.
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