Android 根据包名默认APP允许安装未知来源

    private void openAppInstallUnknownSource(Context context){
        try {
            String packageName = SystemProperties.get("persist.sys.app_install_unknown_source");
            if(!android.text.TextUtils.isEmpty(packageName)){
                AppOpsManager mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
                PackageManager mPm = context.getPackageManager();
                PackageInfo mPackageInfo = mPm.getPackageInfo(packageName,
                    PackageManager.MATCH_DISABLED_COMPONENTS |
                    PackageManager.MATCH_ANY_USER |
                    PackageManager.GET_SIGNATURES |
                    PackageManager.GET_PERMISSIONS);
                mAppOpsManager.setMode(AppOpsManager.OP_REQUEST_INSTALL_PACKAGES,
                mPackageInfo.applicationInfo.uid, packageName,AppOpsManager.MODE_ALLOWED);
            }
        }catch (Exception e) {
            Log.e(TAG, "Exception" + e);
        }
    }

你可能感兴趣的:(android)