我正在尝试使用常规Runtime.getRuntime.exec()例程在Android 7(三星和索尼)中安装APK 。安装失败,但logcat中出现以下异常:
09-04 14:14:33.932 16623-16623/? D/AndroidRuntime: Calling main entry com.android.commands.pm.Pm
09-04 14:14:33.939 3695-3876/? D/PackageInstaller: installation of android.content.pm.PackageInstaller$SessionParams@a4d2f0e for non-container user 0
09-04 14:14:33.940 16623-16623/? E/Pm: Error
java.lang.NullPointerException
at android.os.Parcel.readException(Parcel.java:1699)
at android.os.Parcel.readException(Parcel.java:1646)
at android.content.pm.IPackageInstaller$Stub$Proxy.createSession(IPackageInstaller.java:249)
at com.android.commands.pm.Pm.doCreateSession(Pm.java:530)
at com.android.commands.pm.Pm.runInstall(Pm.java:369)
at com.android.commands.pm.Pm.run(Pm.java:142)
at com.android.commands.pm.Pm.main(Pm.java:99)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:301)
09-04 14:14:33.941 16623-16623/? I/art: System.exit called, status: 1
09-04 14:14:33.941 16623-16623/? I/AndroidRuntime: VM exiting with result code 1
Run Code Online (Sandbox Code Playgroud)
我尝试实现这一点:
Process proc = Runtime.getRuntime().exec("pm install /sdcard/imo.apk");
Run Code Online (Sandbox Code Playgroud)
所以:
Process proc = Runtime.getRuntime().exec(new String[]{"/system/bin/sh","-c","/system/bin/pm …Run Code Online (Sandbox Code Playgroud)