【问题标题】:Function to check development settings not working as expected检查开发设置的功能未按预期工作
【发布时间】:2019-05-24 13:20:39
【问题描述】:

我有一个功能可以检查是否启用了开发者模式,正如这里的建议:

Android - How to check if Developer option is enabled

代码如下:

public boolean isDevMode() {
    if(Build.VERSION.SDK_INT >= 17) {
        return android.provider.Settings.Global.getInt(getApplicationContext().getContentResolver(),
                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0) != 0;
    } else {
        return false;
    }
}

它在 API 26+ 上完美运行,但我刚刚在 API 24 的模拟器上对其进行了测试,无论是否启用开发人员设置,它都会返回 false。

我错过了什么?

【问题讨论】:

    标签: android


    【解决方案1】:

    通过将默认值更改为 true 来修复它,仅适用于 oreo 下的构建。

    public boolean isDevMode() {
       if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            return Settings.Secure.getInt(context.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
       } else {
            return Settings.Secure.getInt(context.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1) != 0;
       }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-08-29
      • 2020-04-28
      • 2021-08-27
      • 1970-01-01
      • 2012-10-07
      • 2014-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多