I have a media notification and a large icon, my code successfully loads the image first time, but image doesn't changes second time. My code was working in Android 8.1.0, currently I'm using Android 12 and it doesn't work.
mediaSession.setMetadata(new MediaMetadataCompat.Builder()
.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, image)
.putBitmap(MediaMetadata.METADATA_KEY_ART, image)
.putLong(MediaMetadata.METADATA_KEY_DURATION, -1L)
.putString(MediaMetadata.METADATA_KEY_TITLE,BASLIK)
.putString(MediaMetadata.METADATA_KEY_ARTIST,ISIM)
.build());
stateBuilder = new PlaybackStateCompat.Builder();
stateBuilder.setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACT
stateBuilder.setState(PlaybackStateCompat.STATE_PLAYING, 0, 1.0f);
mediaSession.setPlaybackState(stateBuilder.build());
notification = new NotificationCompat.Builder(context, CHANNEL_ID)
.setContentTitle(BASLIK)
.setContentText(ISIM)
.setLargeIcon(image)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.addAction(R.drawable.ic_previous, "Previous", prevPendingIntent)
.addAction(icon, "Play", playPendingIntent)
.addAction(R.drawable.ic_next, "Next", nextPendingIntent)
.setOnlyAlertOnce(true)
.setPriority(Notification.PRIORITY_LOW)
.setOngoing(true)
.setShowWhen(false)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setStyle(new androidx.media.app.NotificationCompat.MediaStyle()
.setShowActionsInCompactView(0, 1, 2)
.setMediaSession(mediaSession.getSessionToken()));
notificationManager.notify(Integer.parseInt(CHANNEL_ID), notification.build());
I tried removing MediaStyle and it worked, images successfully changed each time but I need to use MediaStyle. I'm sure about updating the notification, title and song name changes but image doesn't.
I solved my problem by adding metadata.putLong(MediaMetadata.METADATA_KEY_DURATION, duration);
. duration
variable should be long
and it should always get updated.