0

i have an audio book app that work without a problem until android 11. my problem is when i set mediasession to mediastyle, app media notification won't show anymore. i cant find the problem.

here is my code:

Notification notification = new NotificationCompat.Builder(this, channelId)
            .setLargeIcon(Archive.Cover)
            .setSmallIcon(R.drawable.ic_small)
            .setContentTitle(Archive.getChapterTitle())
            .setContentText(Archive.BookTitle)
            .setOngoing(false)
            .setShowWhen(false)
            .setContentIntent(pendingIntent)
            .setPriority(Notification.PRIORITY_MAX)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .addAction(generateAction(R.drawable.ic_replay_white_36dp, "Rewind", ACTION_REWIND))
            .addAction(action)
            .addAction(generateAction(R.drawable.ic_forward_white_36dp, "Fast Forward", ACTION_FAST_FORWARD))
            .setStyle(new androidx.media.app.NotificationCompat.MediaStyle()
                    .setMediaSession(mediaSession.getSessionToken())
                    .setShowActionsInCompactView(0, 1, 2))
            .build();
Justice
  • 11
  • 3
  • Did you find a solution? – zerstoer Aug 31 '21 at 22:04
  • i found the solution you must set mediasession metadata like below: `mediaSession.setMetadata( new MediaMetadataCompat.Builder() .putString(MediaMetadata.METADATA_KEY_TITLE, activeAudioBook.getChapterTitle()) .putString(MediaMetadata.METADATA_KEY_ARTIST, bookData.BookTitle) .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, activeAudioBook.getDuration()) .build()` – Justice Oct 02 '21 at 15:11

0 Answers0