【问题标题】:Get status of setting: "Control notifications on your lock screen"获取设置状态:“控制锁定屏幕上的通知”
【发布时间】:2017-04-16 15:46:23
【问题描述】:

在 Android 上,您可以在“通知”下设置“控制锁定屏幕上的通知”,作为备份,您可以设置通知的可见性,如 notification Tutorial 中所述。

我的问题是,是否可以获取此设置的状态?

我想要设置状态的原因是为用户提供更多选项,如果他们启用了内容隐藏,但如果他们没有启用,则不会打扰他们。

【问题讨论】:

    标签: android notifications settings


    【解决方案1】:

    是的,这是可能的。有两个常量:

    Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS = "lock_screen_allow_private_notifications"
    Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS = "lock_screen_show_notifications"
    

    但是,由于这些值不是公共 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 notification
      // ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-21
      • 1970-01-01
      • 1970-01-01
      • 2014-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多