Roy*_*erg 8 android android-notifications
在Android 7中,您可以长按通知并选择显示来自所属应用程序的通知,而不显示声音.
对于Android 7,我们必须NotificationManager.areNotificationsEnabled()检查用户是否已阻止您的应用的通知.如何检查用户是否刚刚禁用了应用程序通知的声音?
更新: 问题仍然代表Android 8/O. 我们有一些用户抱怨没有听到任何声音,然后他们在不知情的情况下禁用它,没有我们有机会检查它.
声音在 IMPORTANCE_DEFAULT 及以上启用,因此您可以像这样检查:
@RequiresApi(26)
private boolean hasSoundsEnabled(String channelId) {
NotificationManager manager = getSystemService(NotificationManager.class);
NotificationChannel channel = manager.getNotificationChannel(channelId);
return channel.getImportance() >= NotificationManager.IMPORTANCE_DEFAULT;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
120 次 |
| 最近记录: |