In Android O, we can have different notification channels with different priority level (Importance). In my code, I set the channel importance level to Urgent, that is "Make sound and pop on screen".
But when I go to the notification setting, turn off the channel notification, and then turn it on, the importance level will always reset to medium ("No sound"), which is the default level.
I know we can always change the importance level manually, but is there a way to have it remember the settings before the channel is turned off so that when it is turned on again, it will automatically recover to the settings it has before?
It seems that there is not function for Notifications to remember your importance level. It is not hard to just save the default importance for your channel in your code.
This is my test:
I created a notifications channel with importance level as IMPORTANCE_HIGH at the beginning. Then turn off the notification either from the Settings or the long press on the notification pop up. The importance level becomes IMPORTANCE_NONE. When I turn on the notification again, it becomes IMPORTANCE_LOW.
The following is example code to check if the level has been decreased after you turn off and on your notification channel and set it to your original importance.
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel notificationChannel = notificationManager.getNotificationChannel("your_channel_id");
int importance = notificationChannel.getImportance();
if (importance < NotificationManager.IMPORTANCE_HIGH && importance > 0 ) {
notificationChannel.setImportance(NotificationManager.IMPORTANCE_HIGH);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With