允许或拒绝安装未知来源

在这个/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需要适配,先判断是否有权限,没有的话引导用户进行设置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值