androidnotificationsheads-up-notifications

Android heads-up notification not showing after disable and enable it on application settings


I made heads up notification on my application and it's working well.
But when I disable -> enable it on my application notification settings, I can not see heads up notification anymore.
(It still shows on notification bar, makes sound and vibration, but not on heads-up)

-- The logcat message says.

This issue is not resolved when the app is killed and restarted.
Only works normally again when app is deleted and reinstalled.

Is there any way to solve it?

Thanks for your time.


Edited

I found same issue on sample code
https://github.com/googlearchive/android-Notifications

In this application, set notification style to BIG_PICTURE_STYLE and press launch button. then, you can see heads-up notification, but after set "Sample Social" notification settings off -> on from application notification settings, you can not see heads-up notification anymore.


Solution

  • That is the expected behavior. When the user blocks notifications for a particular notification channel in the notification settings, the importance for that notification channel is reduced. Due to which the notification banner will not show across the top of the device. The user will have to manually set the appropriate settings for the notification channel.

    That would be considered as the user's preference and should not be changed forcibly from the application.

    If for whatever reason you absolutely need the notification for the proper functioning of the application, you can detect if the user has disabled notifications or if the importance of a notification channel has been changed and ask the user to change it. Check this

    If for whatever reason you need to forcibly maintain notification settings, what you can do is to delete notification channels and recreate them with the appropriate importance.

    Note: If you delete a notification channel and create a new channel with this same id, the deleted channel will be un-deleted with all of the same settings it had before it was deleted. Thus, you need to create a channel with a new id.

    To check if notifications are blocked for the application, use NotificationManager.areNotificationsEnabled(). Documentation

    To check if notifications are blocked for a notification channel group, use NotificationChannelGroup.isBlocked(). Documentation

    To check if the importance of a notification channel has been changed:

    1. For API 26 to API 28, use NotificationChannel.getImportance() to see if the notification channel importance has been changed. Note that the importance of a channel cannot be changed programmatically once the channel has been created. Documentation
    2. For API 29 and above, use NotificationChannel.hasUserSetImportance(). Documentation