Notification gets automatically hidden sometime in Android 11
- Dominant language
- Java
- Stars
- 21.9k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
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](https://stackoverflow.com/questions/69318953/service-notification-automatically-gets-hidden-after-few-minutes-in-android-11).
The piece of code that I am using for the notification is
~~~ java
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);
}
~~~
Contributor guide
Assessment
This issue has not been assessed yet.