英文:
Android media notification large icon doesn't change
问题
I have a media notification and a large icon, my code successfully loads the image the first time, but the image doesn't change the second time. My code was working on Android 8.1.0, but currently, I'm using Android 12, and it doesn't work.
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 the image doesn't.
英文:
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.
答案1
得分: 0
我通过添加 metadata.putLong(MediaMetadata.METADATA_KEY_DURATION, duration);
解决了我的问题。duration
变量应该是 long
类型,并且应该始终更新。
英文:
I solved my problem by adding metadata.putLong(MediaMetadata.METADATA_KEY_DURATION, duration);
. duration
variable should be long
and it should always get updated.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论