Apk Silent Installation and apk Installation
The boss asked me to get an automatic update. I wanted to use the Silent Installation. I found some big data code on the Internet. I 'd like to change it and paste it first:
Java code
- /**
- * Silent Software Installation
- * @ Param apkAbsolutePath the path of the apk File
- * @ Return installation result: the obtained result value <br>
- *
- * If the installation is successful,"
- * Pkg:/data/local/tmp/Calculator.apk/nSuccess ", <br>
- * If it fails, there is no ending "Success ".
- */
- Public String silentInstall (String apkAbsolutePath ){
- String [] args = {"pm", "install", "-r", apkAbsolutePath };
- String result = "";
- ProcessBuilder processBuilder = new ProcessBuilder (args );
- Process process = null;
- InputStream errIs = null;
- InputStream inIs = null;
- Try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
- Int read =-1;
- Process = processBuilder. start ();
- ErrIs = process. getErrorStream ();
- While (read = errIs. read ())! =-1 ){
- Baos. write (read );
- }
- Baos. write ("/n". getBytes ());
- InIs = process. getInputStream ();
- While (read = inIs. read ())! =-1 ){
- Baos. write (read );
- }
- Byte [] data = baos. toByteArray ();
- Result = new String (data );
- } Catch (IOException e ){
- E. printStackTrace ();
- } Catch (Exception e ){
- E. printStackTrace ();
- } Finally {
- Try {
- If (errIs! = Null ){
- ErrIs. close ();
- }
- If (inIs! = Null ){
- InIs. close ();
- }
- } Catch (IOException e ){
- E. printStackTrace ();
- }
- If (process! = Null ){
- Process. destroy ();
- }
- }
- Return result;
- }
Don't worry, it's over. Remember to add permissions:
Java code
- <! -- The permissions required for installing apk silently -->
- <Uses-permission android: name = "android. permission. INSTALL_PACKAGES"/>
- <Uses-permission android: name = "android. permission. DELETE_PACKAGES"/>
- <Uses-permission android: name = "android. permission. CLEAR_APP_CACHE"/>
- <Uses-permission android: name = "android. permission. CLEAR_APP_USER_DATA"/>
- <Uses-permission android: name = "android. permission. READ_PHONE_STATE"/>
I pasted it. Wow, a lot of black tea and tea ~ What's going on, move the mouse up and look at it,
Java code
- Permission is only granted to system apps
This is a system application ~~ After searching for a long time, I heard a voice saying "clean", so I cleaned it,
Digging! @ No black tea or tea ~ I don't know how to change mainfest and black tea later. I cleaned it again and it turned out to be useful! Therefore, if an error occurs in the future, please remember to clean it first. Of course, if there is something wrong with the layout file, there is no way to do it. You must first let the layout file disappear to make it clean.