android - Android:如何以编程方式禁用通知通道?
问题描述
我有一个有效的实现,以检查是否启用了通道。
但是有没有办法以编程方式禁用通知通道?
我如何检查通道是否已启用:
/**
* Get the setting a user has applied to the notification channel.
* If the android API level is < 26, it will return true if all notification
* are enabled in general, false otherwise.
*
* @return true if the channel is enabled, false otherwise
*/
public static boolean isChannelEnabled(String channelId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
final NotificationManager notificationManager = App.get().getSystemService(NotificationManager.class);
if (notificationManager == null) {
return true;
} else {
final NotificationChannel c = notificationManager.getNotificationChannel(channelId);
final boolean overallEnabled = notificationManager.areNotificationsEnabled();
return overallEnabled && c != null && NotificationManager.IMPORTANCE_NONE != c.getImportance();
}
} else {
return NotificationManagerCompat.from(App.get()).areNotificationsEnabled();
}
}
解决方案
推荐阅读
- excel - 如何检查超链接是否打开 PDF 或在 Excel 中返回“未找到”错误
- c# - .net 5.0 库可用于 VBA
- python - CondaError:尝试使用 conda 下载 cudnn 时,下载的字节与 Content-Length 不匹配
- reactjs - React 如何从多个 url 获取数据
- google-play - Google Play 发布前报告屏幕截图的方向不正确
- go - 如何减少这个 go 程序的内存占用?
- triggers - 触发器触发了两次,但第一次运行是空的?
- javascript - 我如何找到变量:react-native 中的名称?
- powershell - Powershell IDE:如何在不离开 Powershell ISE 的情况下重新启动交互式 shell 以清除所有变量?
- c# - C# json反序列化器如何设置属性