Android MediaStyle Notification image (largeIcon) is pixilated

778 Views Asked by At

I'm trying to show a media style notification, and I'm grabbing the image for the art from my app's local files directory by Uri. When the same exact same image is shown in my app (via coil's AsyncImage) it displays in perfect quality, but when the image is shown in the notification, it's horribly pixilated and blurry.

I'm creating the bitmap for the notification using ImageDecoder.decodeBitmap, providing it a source using ImageDecoder.createSource (I've tried both using the content resolver and Uri as a source and using File(Uri.path) as a source, both give the same result).

I then use setLargeIcon providing the bitmap created.

Strangely enough, when I log the bitmap's width and height after being created and before being passed to setLargeIcon, it reports the same dimensions as the original image, so it seems fine before it's passed to the media style notification.

Any ideas?

2

There are 2 best solutions below

1
toto263 On

Please try to use setMetadata() of MediaSessionCompat.

MediaSessionCompat mediasession = new MediaSessionCompat(..);
MediaMetadataCompat.Builder bld = new MediaMetadataCompat.Builder();
//put metadata such as title, artist...
bld.putBitmap(BITMAP_FROM_RESOURCE);
mediaSession.setMetadata(bld.build());

The MediaStyle notification doesn't seem to use the image from setLargeIcon.

0
joe_vettek On

This issue first appeared on presumably Android 12. Previously, there was no need to specifically set the bitmap on Android 10. So if it is an old device, you can still use setLargeIcon. But Android 10+ is better to use the standard method.

By the way, METADATA_KEY_ALBUM_ART can also be used as a key value to put into a bitmap.

builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, yourBitmap)