需要在实现的app上加上 android.uid.system和系统签名,然后执行以下方法
private void silenceUninstall(String packageName) {
try {
PackageManager pm = this.getPackageManager();
Method[] methods = pm!=null?pm.getClass().getDeclaredMethods():null;
Method mDel = null;
if (methods != null && methods.length>0) {
for (Method method : methods) {
if (method.getName().toString().equals("deletePackage")) {
mDel = method;
break;
}
}
}
if (mDel != null) {
mDel.setAccessible(true);
mDel.invoke(pm,packageName,null,0);
}
} catch (Exception e) {
e.printStackTrace();
}
}
此方法通过反射调用packagemanager的deletepackage方法实现
标签:methods,android9,mDel,method,静默,卸载,null,Method,pm From: https://blog.51cto.com/u_16228977/7388533