-
Notifications
You must be signed in to change notification settings - Fork 6k
Open
Labels
Description
I am trying to show the music player's notification using PlayerNotificationManager but the notification is automatically getting hidden under some condition (may be when there is lots of other notifications) even when audio is being played. But the notification gets shown again when the state of the player gets changed, for example if I pause the audio the notification reappears on its own. Also I believe that it is only in Android 11.
I have even looked at all the articles available in the internet from last three days and tried to fix it but nothing is working so I thought to take help here, so hope someone gets me back about it.
I have even asked a question in stackoverflow.
The piece of code that I am using for the notification is
private void createNotification() {
PlayerNotificationManager.NotificationListener listener = new PlayerNotificationManager.NotificationListener() {
@Override
public void onNotificationCancelled(int notificationId, boolean dismissedByUser) {
stopSelf();
}
@Override
public void onNotificationPosted(int notificationId, Notification notification, boolean ongoing) {
startForeground(notificationId, notification);
}
};
playerNotificationManager = new PlayerNotificationManager.Builder(this, NOTIFICATION_ID, NOTIFICATION_CHANNEL)
.setMediaDescriptionAdapter(new DescriptionAdapter())
.setNotificationListener(listener)
.setCustomActionReceiver(new CustomActionReceiver())
.setChannelNameResourceId(R.string.channel)
.setChannelImportance(NotificationUtil.IMPORTANCE_HIGH)
.build();
mediaSession = new MediaSessionCompat(getApplicationContext(), getResources().getString(R.string.app_name));
mediaSession.setActive(true);
playerNotificationManager.setMediaSessionToken(mediaSession.getSessionToken());
mediaSessionConnector = new MediaSessionConnector(mediaSession);
mediaSessionConnector.setPlayer(exoPlayer);
playerNotificationManager.setPlayer(exoPlayer);
}
Reactions are currently unavailable