Android Oreo 通知 - 检查是否启用了特定频道 [英] Android Oreo Notifications - check if specific channel enabled
本文介绍了Android Oreo 通知 - 检查是否启用了特定频道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此代码段检查是否启用了通知:
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.
有什么想法吗?
推荐答案
具有向后兼容性:
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();
}
}
这篇关于Android Oreo 通知 - 检查是否启用了特定频道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文