App Rogue Dafa apk silent installation

Source: Internet
Author: User

Boss want me to get an automatic update, to use the silent installation, online found some danale code, I take to change it, first paste it out:

Java code
  1. /**
  2. * Software Silent Installation
  3. * @param apkabsolutepath apk file path
  4. * @return Installation Result: Obtained result value <br>
  5. *
  6. * If the installation is successful, "
  7. * Pkg:/data/local/tmp/calculator.apk/nsuccess ",<br>
  8. * If it is a failure, then 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, don't stop, remember to add permission:

Java code
    1. <!--The following are the permissions required to install the 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 paste the past, wow, a lot of black tea ~ How, the mouse moved up a look,

Java code
    1. Permission is only granted to system apps

Strange class, I this is the system application AH ~ ~ For a long time, heard a voice said to clean under, so, I clean a bit,

Dig on! @ really did not have black tea class ~ Later did not know how to change the next mainfest, and black tea, I also clean a bit, unexpectedly still useful! So, after the error, remember to clean the first OH. Of course, if you have the wrong layout file, then there is no way, you need to let the layout file to the error disappears before clean.

App Rogue Dafa apk silent installation

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.