I'm using the following call to check whether notifications are enabled:
NotificationManagerCompat.from(getContext()).areNotificationsEnabled()
However, if a user disables only the channel, I cannot know about it.
How do I check whether a specific notification channel is enabled?
with backwards compatibility:
public boolean isNotificationChannelEnabled(Context context, @Nullable String channelId){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if(!TextUtils.isEmpty(channelId)) {
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = manager.getNotificationChannel(channelId);
return channel.getImportance() != NotificationManager.IMPORTANCE_NONE;
}
return false;
} else {
return NotificationManagerCompat.from(context).areNotificationsEnabled();
}
}