areNotificationsEnabled 和 areNotificationsPaused 是 Android 平台中 NotificationManagerCompat 类的两个方法。 areNotificationsEnabled 是用来检查应用是否被授予了发送通知的权限,返回布尔值,true 表示应用具有发送通知的权限,false 则表示应用未被授权发送通知。 areNotificationsPaused 是用来检查是否有通知被暂停发送,返回布尔值。当返回 true 时,表示当前处于某种静音模式,不会发送任何通知。
示例代码:
// 检查是否有通知被暂停
boolean isPaused = NotificationManagerCompat.from(this)
.areNotificationsPaused();
// 检查应用是否有发送通知的权限
boolean isEnabled = NotificationManagerCompat.from(this)
.areNotificationsEnabled();
上一篇:areNotificationsEnabled()和checkSelfPermission(this,Manifest.permission.POST_NOTIFICATIONS)之间有什么不同?