I updated my code to API v26, set up NotificationChannels and I can see my notifications, but I have logic regarding disabled notifications. Before 26 I have something like:
NotificationManagerCompat.from(context).areNotificationsEnabled()
And this seems to be not useful now. So how can one know if notification channel is disabled in the settings?
1 Answers
Answers 1
I found that new ChannelNotification
approach doesn't replace old logic, it adds one more layer of control for notifications. So now we have 2 scenarios, see Screenshot:
You can define if notifications enabled:
NotificationManagerCompat.from(context).areNotificationsEnabled();
You can define if your notification is visible to user:
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel notificationChannel = notificationManager.getNotificationChannel(channelId); int importance = notificationChannel.getImportance();
If importance is NotificationManager.IMPORTANCE_NONE
user will not see notification, but the notification is there, so you can use it with Foreground service and you should dismiss it. If importance is NotificationManager.IMPORTANCE_MIN
or higher user will see notification.
0 comments:
Post a Comment