android - 查看通知 channel 是否被用户静音

标签 android android-notifications

在我的 Android 应用程序中有一个长时间运行的服务(导出数据),它显示进度并以通知用户共享导出的文件结束。需要明确的是,这不是推送通知,而是 Notificationnew NotificationCompat.Builder(…).set…().build() 在本地创建.

有相当多的用户将通知 channel 静音(或全局禁用我的应用程序的通知)。我不知道为什么,因为它真的不是很冗长,顺便说一句。但这些用户觉得该应用程序无法正常工作。如果通知被静音,我想警告他们。

我能预先知道某个特定的 NotificationChannel 是否存在吗?被用户静音了吗?

我只找到了 NotificationManager.areNotificationsEnabled()但我不确定它是否有其他用途。

最佳答案

我相信您可以结合使用以下两种方法来检测特定 channel 或整个包的通知是否被阻止。

来自官方文档

isBlocked()

public boolean isBlocked ()
Returns whether or not notifications posted to channels belonging to this group are blocked. This value is independent of NotificationManager.areNotificationsEnabled() and NotificationChannel.getImportance().

areNotificationsEnabled()

public boolean areNotificationsEnabled ()
Returns whether notifications from the calling package are blocked.

关于android - 查看通知 channel 是否被用户静音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54198989/

相关文章:

android - 如何在像 Wifi Analyzer App 这样的 Android 中绘制图表?

Android:强制数据/文件在SD卡上

android - 如何实现具有不同行数项目的 RecyclerView?

android - 从 Android 中的 WebView 获取所有图像

android - 如何在android通知中增加remoteview的高度

android - 使用保存的图标创建通知

android - 我如何在android中设置不闪烁的通知灯

Android Auto 通知未显示

java - 安排通知?

android 通知大图像不工作