android8.1系统静默安装问题(无须手动点击)

 public String silentInstallApkByReflect(String apkPath) {
        LogUtils.d(TAG,"启动了静默升级!");
//        SharedConfig.getInstance(this).writeData(AppConfig.Key.UPGRADE_RESULT,true);
        String result = "false";
        try {
            PackageManager packageManager = getPackageManager();
            Class pmClz = packageManager.getClass();
            if (Build.VERSION.SDK_INT >= 21) {
                Class aClass = Class.forName("android.app.PackageInstallObserver");
                Constructor constructor = aClass.getDeclaredConstructor();
                constructor.setAccessible(true);
                Object installObserver = constructor.newInstance();
                Method method = pmClz.getDeclaredMethod("installPackage", Uri.class, aClass, int.class, String.class);
                method.setAccessible(true);
                method.invoke(packageManager, Uri.fromFile(new File(apkPath)), installObserver, 2, null);
            } else {
                Method method = pmClz.getDeclaredMethod("installPackage", Uri.class,
                        IPackageInstallObserver.class, int.class, String.class);
                method.setAccessible(true);
                method.invoke(packageManager, Uri.fromFile(new File(apkPath)), null, 2, null);
            }
            result = "success";
        } catch (Exception e) {
            e.printStackTrace();
            LogUtils.d(TAG, e.getMessage());
            result = e.toString();
        }
        return result;
    }

所需jar包:https://download.csdn.net/upload/11139326

 

获取签名文件

platform.pk8和platform.x509.pem,android系统源码路径build\target\product\security

得到签名工具signapk.jar

signapk.jar是由源码路径下/platform/build/tools/signapk/编译产生,可以在源码路径下/out/host/linux-x86/framework/中

签名指令:java -jar signapk.jar platform.x509.pem platform.pk8 old.apk new.apk

 

你可能感兴趣的:(android源码相关)