Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: cannot find symbol class MediaStyle after migrating to androidx

android.support.v4.media.app.NotificationCompat.MediaStyle() was working fine in a music player application but after migrating to android x I get this error: cannot find symbol class MediaStyle. Any help would be appreciated thanks.

like image 968
nivla360 Avatar asked Jun 05 '19 09:06

nivla360


4 Answers

In AndroidX, that specific style is located in a different package. You need to prepend the media style with 'androidx.media.app'.

In other words:

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

Curiously enough, I didn't need to implement this package in my gradle file, so it could be something related to AndroidX internal dependencies.

like image 66
jmart Avatar answered Nov 17 '22 08:11

jmart


for my case, i need to add the following to my gradle file to find NotificationCompat.MediaStyle() class.

implementation "androidx.media:media:1.1.0"

https://developer.android.com/jetpack/androidx/releases/media

NotificationCompat.Builder(this, CHANNEL_ID)
.setStyle(new androidx.media.app.NotificationCompat.MediaStyle());

note that notificationCompat.Builder is in a different package (androidx.core.app.NotificationCompat) from MediaStyle.

like image 41
Angel Koh Avatar answered Nov 17 '22 09:11

Angel Koh


Migrate android.support.v4.media.app.NotificationCompat to androidx.core.app.NotificationCompat

This looks like same answer @karan gave above. But the classes are different. Took me days to figure out that androidx.media.app.NotificationCompat was my problem.

The difference between the two; one is androidx.core..., the other is androidx.media...

like image 25
aphoe Avatar answered Nov 17 '22 09:11

aphoe


As you have migrated to androidX you need to use equivalent import for classes instead of using older support library classes.

Thus, replace android.support.v4.media.app.NotificationCompat with this androidX class androidx.media.app.NotificationCompat. You can check migration guide further from here https://developer.android.com/jetpack/androidx/migrate

like image 2
karan Avatar answered Nov 17 '22 09:11

karan