error: cannot find symbol class MediaStyle after migrating to androidx

Viewed 6452

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.

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.

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.

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...

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

Related