【问题标题】:Android - get INSTALL_NON_MARKET_APPS booleanAndroid - 获取 INSTALL_NON_MARKET_APPS 布尔值
【发布时间】:2013-07-21 21:12:49
【问题描述】:

我试图绕过具有两个不同版本的 INSTALL_NON_MARKET_APPS 选项。 17 岁之前的 API 级别和 17 岁以上。运行时出现空指针异常:

boolean unknownSource = false;
if (Build.VERSION.SDK_INT < 17) {
    unknownSource = Settings.Secure.getInt(null, Settings.Secure.INSTALL_NON_MARKET_APPS, 0) == 1;
} else {
    unknownSource = Settings.Global.getInt(null, Settings.Global.INSTALL_NON_MARKET_APPS, 0) == 1;
}

【问题讨论】:

    标签: android


    【解决方案1】:

    我认为是 API 级别 3,Settings.System 变量已贬值并更改为 Settings.Secure,然后在 API 级别 17 中更改为 Settings.Global

    另外,我认为方法调用需要上下文内容解析器。

    boolean unknownSource = false;
    if (Build.VERSION.SDK_INT < 3) {
        unknownSource = Settings.System.getInt(getContentResolver(), Settings.System.INSTALL_NON_MARKET_APPS, 0) == 1;
    }
    else if (Build.VERSION.SDK_INT < 17) {
        unknownSource = Settings.Secure.getInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS, 0) == 1;
    } else {
        unknownSource = Settings.Global.getInt(getContentResolver(), Settings.Global.INSTALL_NON_MARKET_APPS, 0) == 1;
    }
    

    【讨论】:

    猜你喜欢
    • 2016-08-13
    • 1970-01-01
    • 2019-05-13
    • 2016-07-08
    • 2012-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-01
    相关资源
    最近更新 更多