1

我试图绕过具有两个不同版本的 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;
}
4

1 回答 1

3

我相信是 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;
}
于 2013-07-21T21:21:18.307 回答