Im using this snippet to check if notifications enabled:
NotificationManagerCompat.from(getContext()).areNotificationsEnabled()
however, if user disable only the channel, i cannot know about it.
Any idea?
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(); } }
Check out the docs here.
Users can modify the settings for notification channels, including behaviors such as vibration and alert sound. You can call the following two methods to discover the settings a user has applied to a notification channel:
To retrieve a single notification channel, you can call
getNotificationChannel()
. To retrieve all notification channels belonging to your app, you can callgetNotificationChannels()
. After you have theNotificationChannel
, you can use methods such asgetVibrationPattern()
andgetSound()
to find out what settings the user currently has. To find out if a user blocked a notification channel, you can callgetImportance()
. If the notification channel is blocked,getImportance()
returnsIMPORTANCE_NONE
.
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