android - 检查 Android 用户的 "when device is locked"通知设置

标签 android android-5.0-lollipop

在 Android L 上,只有当用户设置设置为“显示所有通知内容”时,我才想在锁定屏幕上向用户显示通知,否则内容将毫无意义,我只是不想在以下位置显示通知全部。

知道如何在代码中验证用户通知设置吗?

谢谢!

最佳答案

你需要阅读

Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS = "lock_screen_allow_private_notifications"

Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS = "lock_screen_show_notifications"

只有当两者都为 1 时,您才需要显示您的通知。 但是由于这些值不是公共(public) api 的一部分,因此这些值将来可能会发生变化,或者可能无法在所有设备上工作

int show_all = Settings.Secure.getInt(getContentResolver(),"lock_screen_allow_private_notifications", -1); 
int noti_enabled = Settings.Secure.getInt(getContentResolver(),"lock_screen_show_notifications", -1); 

if(show_all > 0 && noti_enabled > 0){
//post noti
}

关于android - 检查 Android 用户的 "when device is locked"通知设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27768345/

相关文章:

android - 如何更改 Timepicker Style 轮?

android - 为什么我不能在 Android Studio 中将任何东西拖到 'activity_main.xml' 上?

android - 有关GcmTaskService的一些问题

android - 如何根据 SDK 版本选择 Activity 从启动器启动?

android - CoordinatorLayout.Behavior : how to set it programmatically

android - Android 4.3 上的 YouTube 嵌入式播放器

java - 你如何在 Android 的 arrayList 中的文本旁边添加图像?

android - 单击按钮开始新线程

Android 在任务锁定时运行另一个应用程序

android - 在 Lollipop 设备上使用 AppCompat-21 崩溃