开始客户让我们执行下面的CMD 代码
adb shell appops set com.android.chrome REQUEST_INSTALL_PACKAGES allow
后来
GTP 告诉我有 Setmode的方法,后面在设置里面找到了 OP_REQUEST_INSTALL_PACKAGES 这个,里面有个方法mAppOpsManager.setMode(AppOpsManager.OP_REQUEST_INSTALL_PACKAGES,
uid, mPackageName,
newState ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_ERRORED);
刚好就是传入包名的
下面的代码加在 设置里面,然后通过广播去执行
A11 测试可用
private void setCanInstallApps(String mPackageName , boolean newState) {int uid = 0;try {uid = mPackageManager.getPackageInfo(mPackageName, 0).applicationInfo.uid;} catch (PackageManager.NameNotFoundException e) {e.printStackTrace();}Log.d(TAG, "install apppppppppppppppp ->line313 uid ="+uid);mAppOpsManager.setMode(AppOpsManager.OP_REQUEST_INSTALL_PACKAGES,uid, mPackageName,newState ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_ERRORED);}