允许或拒绝安装未知来源

在这个/packages/SettingsProvider/res/values/defaults.xml
 <bool name="def_bluetooth_on">false</bool>
     <bool name="def_wifi_display_on">false</bool>
-    <bool name="def_install_non_market_apps">false</bool>
+    <bool name="def_install_non_market_apps">true</bool>
     <bool name="def_package_verifier_enable">true</bool>
     <!-- Comma-separated list of location providers.
          Network location is off by default because it requires
中将
def_install_non_market_apps的值置为true即可





代码中:


方法

public static boolean EnableOrDisableUnknownSource(Context context, boolean isOpen){
    boolean success = false;
    int result = Settings.Secure.getInt(context.getContentResolver(),
            Settings.Secure.INSTALL_NON_MARKET_APPS, 0);
    LogUtils.d("enable install unknown source result : "+result);
    if (result == 0 && isOpen) {
        success = Settings.Secure.putString(context.getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS, "1");
    }else if(!isOpen){
        success = Settings.Secure.putString(context.getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS, "0");

    }
    LogUtils.d("enable install unknown source : "+success);
    return success;
}


添加权限:
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>




原文地址:

设置的源码及与未知来源相关的代码

https://blog.csdn.net/adayabetter/article/details/43407637



Android O安装未知来源

http://baijiahao.baidu.com/s?id=1577241378718915266&wfr=spider&for=pc


根据代码描述流程

https://blog.csdn.net/ounuo5280/article/details/50587752


Settings源码:
https://blog.csdn.net/adayabetter/article/details/43407637

Android O去除“允许未知来源”选项,需手动确认
http://baijiahao.baidu.com/s?id=1577241378718915266&wfr=spider&for=pc

第三方lib包
com.symbol.emdk.*; 的使用
https://bbs.csdn.net/topics/392347147

代码实现
https://stackoverflow.com/questions/19026554/turn-on-unknown-sources-setting-programatically?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa





2、需要注意的地方

在android8.0系统中,无法自动安装打开app,其他低于8.0的没问题。原因就是,8.0系统限制了未知来源的应用安装的权限。解决方案是,android8.0需要适配,先判断是否有权限,没有的话引导用户进行设置

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页