这个转自 : https://blog.csdn.net/u013270171/article/details/893208241.静默安装-------系统签名/** * void installPackageAsUser(in String originPath, * in IPackageInstallObserver2 observer, * int flags, * in String installerPackageName, * int userId); * @param installPath */public static void installApkInSilence(String installPath,String packageName) {    Class<?> pmService;    Class<?> activityTherad;    Method method;    try {        activityTherad = Class.forName("android.app.ActivityThread");        Class<?> paramTypes[] = getParamTypes(activityTherad, "getPackageManager");        method = activityTherad.getMethod("getPackageManager", paramTypes);        Object PackageManagerService = method.invoke(activityTherad);        pmService = PackageManagerService.getClass();        Class<?> paramTypes1[] = getParamTypes(pmService, "installPackageAsUser");        method = pmService.getMethod("installPackageAsUser", paramTypes1);        method.invoke(PackageManagerService, installPath, null, 0x00000040, packageName, getUserId(Binder.getCallingUid()));//getUserId    } catch (ClassNotFoundException e) {        e.printStackTrace();    } catch (NoSuchMethodException e) {        e.printStackTrace();    } catch (IllegalAccessException e) {        e.printStackTrace();    } catch (InvocationTargetException e) {        e.printStackTrace();    }}private static Class<?>[] getParamTypes(Class<?> cls, String mName) {    Class<?> cs[] = null;    Method[] mtd = cls.getMethods();    for (int i = 0; i < mtd.length; i++) {        if (!mtd[i].getName().equals(mName)) {            continue;        }        cs = mtd[i].getParameterTypes();    }    return cs;}private static final int PER_USER_RANGE = 100000;private static int getUserId(int uid) {    return uid / PER_USER_RANGE;}

 

这个卸载忘了是哪位老哥的了 抱歉

/** * 静默卸载 系统签名 */private void quietUnInstallApk() {    if (checkDeviceAdminEnabled()) {        Intent intent = new Intent();        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        PendingIntent sender = PendingIntent.getActivity(getActivity(), 0, intent, 0);        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {            PackageInstaller mPackageInstaller = getActivity().getPackageManager().getPackageInstaller();            mPackageInstaller.uninstall("com.mcy.adbcommanddemo", sender.getIntentSender());// 卸载APK        }    } else {        ToastUtil.show("Not Admin");    }}

更多相关文章

  1. Android 显示系统 --- Surface Flinger
  2. [置顶] Android——4.2.2 文件系统目录分析
  3. Android给第三方应用添加系统签名的两种方式
  4. Intent打开系统设置界面(action列表)
  5. android 在调用执行了reboot系统层做部分针对平台进行特殊处理
  6. android获取各种系统路径的方法

随机推荐

  1. android viewholder
  2. android EditText 去除边框
  3. Android(安卓)通知的基本用法示例代码
  4. 布局的学习
  5. Android上发送带附件的邮件
  6. Android(安卓)TelephonyManager类
  7. Android(安卓)Studio里面Failed to resol
  8. Android编译系统
  9. android 9.0 bindService绑定Servcie的过
  10. android okhttp+Retrofit 发送带有/ ^等