Android的 - 让INSTALL_NON_MARKET_APPS布尔 [英] Android - get INSTALL_NON_MARKET_APPS boolean

查看:1095
本文介绍了Android的 - 让INSTALL_NON_MARKET_APPS布尔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图绕过INSTALL_NON_MARKET_APPS选项有两个不同的版本。一个pre-17 API级和17+。当我运行此我得到一个空指针异常:

 布尔unknownSource = FALSE;
如果(Build.VERSION.SDK_INT&所述; 17){
    unknownSource = Settings.Secure.getInt(NULL,Settings.Secure.INSTALL_NON_MARKET_APPS,0)== 1;
} 其他 {
    unknownSource = Settings.Global.getInt(NULL,Settings.Global.INSTALL_NON_MARKET_APPS,0)== 1;
}
 

解决方案

我相信这是API级别3的 Settings.System 变量是德preciated和改变了以 Settings.Secure ,然后在API级别17它改变了以 Settings.Global

另外,我相信在方法调用,需要上下文内容解析器。

 布尔unknownSource = FALSE;
如果(Build.VERSION.SDK_INT 3;){
    unknownSource = Settings.System.getInt(getContentResolver(),Settings.System.INSTALL_NON_MARKET_APPS,0)== 1;
}
否则,如果(Build.VERSION.SDK_INT< 17){
    unknownSource = Settings.Secure.getInt(getContentResolver(),Settings.Secure.INSTALL_NON_MARKET_APPS,0)== 1;
} 其他 {
    unknownSource = Settings.Global.getInt(getContentResolver(),Settings.Global.INSTALL_NON_MARKET_APPS,0)== 1;
}
 

I am trying to get around the INSTALL_NON_MARKET_APPS option which has two different versions. A pre-17 API level and 17+. I get a null pointer exception when I run this:

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;
}

解决方案

I believe it is API level 3 that the Settings.System variable was depreciated and changed over to Settings.Secure and then in API level 17 it changed over to Settings.Global.

Also, I believe the method call requires a Context Content Resolver.

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;
}

这篇关于Android的 - 让INSTALL_NON_MARKET_APPS布尔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆