Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NotificationCompat.setStyle() can't get Notification.MediaStyle

I've found out that the MediaStyle setStyle is not working when I'm using NotificationCompat.builder(this) to make a notification.

I mean, When using this on NotificationCompat.Builder(this):

.setStyle(new Notification.MediaStyle()
         .setMediaSession(mySession))

It saying it wants to get NotificationCompat.style instead of Notification.MediaStyle.

Can you help me solve that problem? Is there any replacement for the NotificationCompat?

Thanks.

like image 231
user3184899 Avatar asked Sep 05 '25 10:09

user3184899


1 Answers

For AndroidX in 2020 you can use following code -

builder.setStyle(new androidx.media.app.NotificationCompat.MediaStyle());

don't forget to add the androidx.media dependency in build.gradle(Module:app)

implementation "androidx.media:media:1.2.0"
like image 95
VikaS GuttE Avatar answered Sep 08 '25 00:09

VikaS GuttE