Apk Silent Installation and apk Installation

Source: Internet
Author: User

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  
  1. /**
  2. * Silent Software Installation
  3. * @ Param apkAbsolutePath the path of the apk File
  4. * @ Return installation result: the obtained result value <br>
  5. *
  6. * If the installation is successful,"
  7. * Pkg:/data/local/tmp/Calculator.apk/nSuccess ", <br>
  8. * If it fails, there is no ending "Success ".
  9. */
  10. Public String silentInstall (String apkAbsolutePath ){
  11. String [] args = {"pm", "install", "-r", apkAbsolutePath };
  12. String result = "";
  13. ProcessBuilder processBuilder = new ProcessBuilder (args );
  14. Process process = null;
  15. InputStream errIs = null;
  16. InputStream inIs = null;
  17. Try {
  18. ByteArrayOutputStream baos = new ByteArrayOutputStream ();
  19. Int read =-1;
  20. Process = processBuilder. start ();
  21. ErrIs = process. getErrorStream ();
  22. While (read = errIs. read ())! =-1 ){
  23. Baos. write (read );
  24. }
  25. Baos. write ("/n". getBytes ());
  26. InIs = process. getInputStream ();
  27. While (read = inIs. read ())! =-1 ){
  28. Baos. write (read );
  29. }
  30. Byte [] data = baos. toByteArray ();
  31. Result = new String (data );
  32. } Catch (IOException e ){
  33. E. printStackTrace ();
  34. } Catch (Exception e ){
  35. E. printStackTrace ();
  36. } Finally {
  37. Try {
  38. If (errIs! = Null ){
  39. ErrIs. close ();
  40. }
  41. If (inIs! = Null ){
  42. InIs. close ();
  43. }
  44. } Catch (IOException e ){
  45. E. printStackTrace ();
  46. }
  47. If (process! = Null ){
  48. Process. destroy ();
  49. }
  50. }
  51. Return result;
  52. }

 

Don't worry, it's over. Remember to add permissions:

 

Java code  
  1. <! -- The permissions required for installing apk silently -->
  2. <Uses-permission android: name = "android. permission. INSTALL_PACKAGES"/>
  3. <Uses-permission android: name = "android. permission. DELETE_PACKAGES"/>
  4. <Uses-permission android: name = "android. permission. CLEAR_APP_CACHE"/>
  5. <Uses-permission android: name = "android. permission. CLEAR_APP_USER_DATA"/>
  6. <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  
  1. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.