Recently, an android project requires the software to automatically download and install the specified APK file without user operations, that is, Silent Installation. After reading Google and combining the methods, I found a relatively simplified method. However, this method was only tested in Android 4.0, you can try this method in other versions. To perform Silent Installation, you must have the permission to execute the PM install command. There are two steps in preparation: 1. Get the execution permission. 2. Execute the command. First, we will introduce the second step. How to execute the PM install command: Key Code In fact, there is one sentence:
Runtime.getruntime(cmd.exe C ("PM install xxx.apk ");
Some people also mentioned on the Internet that they used bufferreader to read the output success from the console to determine whether the installation was successful, but I never caught the success, you have to use the volume er of package install to handle the operation after successful installation. Return to how to obtain permissions. 1. First, we need to use the source code of the Android system./Build/target/product/security directory , Find two signature files: Platform. x509.pem and platform. pk8 2. Find the source code of the signapk. jar file in the/build/tools/signapk directory and compile it into the signapk. jar file. 3. Add the install_packages permission to the manifest. xml file of the android project. 4. Export the APK file. Select "Export signature file" here. Right-click the project and choose "android Tools"> "Export signed application package..." 5. Execute jar signapk. Jar platform. X509 . Pem platform. pk8 signed APK target file. APK the generated target file APK can be installed in Android normally, and any specified APK file can be installed silently.
Download the following three files:
Signapk. Jar
Platform. x509.pem
Platform. pk8
Publish by note