[Excerpt] Two Methods for installing APK silently in Android

Source: Internet
Author: User
I am very busy during this time. I am too busy to post a post. I will try again today ....

Silent Installation on Android seems to be a very attractive feature. Many people have asked this question. Today I will share two methods for implementing Silent Installation, but after reading this articleArticleBut it will still disappoint some people.
Android divides all permission into four levels based on its potential risks (the attribute is protectionlevel): "normal", "dangerous", "signature", and "signatureorsystem ". Install_packages belongs to the latter two. Let's take a look at the descriptions of the last two types in the official documents.

"Signature": A permission that the system grantsOnly if the requesting application is signed with the same certificate as the application that declared the permission.If the certificates match, the system automatically grants the permission without policying the user or asking for the user's explicit approval.

"Signatureorsystem": A permission that the system grantsOnly to applications that are in the Android system imageOr that areSigned with the same certificates as those in the system image.Please avoid using this option, as thesignature protection level shocould be sufficient for most needs and works regardless of exactly where applications are installed. the "signatureorsystem" permission is used for certain special situations where multiple vendors have applications built into a system image and need to share specific features explicitly because they are being built together.

Therefore, the two methods described here require the following harsh conditions:
1. built-in to Rom. The installation location of the APK package is/system/app.
2. Use the same signature of the APK installation system as the target.
Well, regardless of these harsh conditions, the following describes how to compileCodeHere, use the PM install <apk_path> command, instead of the complicated undisclosed packagemanager. Install () method.

  1. // This code come form sodino. Email: sodinoopen@hotmail.com
  2. String [] ARGs = {"PM", "Install", "-R", apkabsolutepath };
  3. String result = "";
  4. Processbuilder = new processbuilder (ARGs );
  5. Process = NULL;
  6. Inputstream erris = NULL;
  7. Inputstream inis = NULL;
  8. Try {
  9. Bytearrayoutputstream baos = new bytearrayoutputstream ();
  10. Int READ =-1;
  11. Process = processbuilder. Start ();
  12. Erris = process. geterrorstream ();
  13. While (read = erris. Read ())! =-1 ){
  14. Baos. Write (read );
  15. }
  16. Baos. Write ('\ n ');
  17. INIS = process. getinputstream ();
  18. While (read = inis. Read ())! =-1 ){
  19. Baos. Write (read );
  20. }
  21. Byte [] DATA = baos. tobytearray ();
  22. Result = new string (data );
  23. } Catch (ioexception e ){
  24. E. printstacktrace ();
  25. } Catch (exception e ){
  26. E. printstacktrace ();
  27. } Finally {
  28. Try {
  29. If (erris! = NULL ){
  30. Erris. Close ();
  31. }
  32. If (INIS! = NULL ){
  33. INIS. Close ();
  34. }
  35. } Catch (ioexception e ){
  36. E. printstacktrace ();
  37. }
  38. If (process! = NULL ){
  39. Process. Destroy ();
  40. }
  41. }
  42. Return result;

Copy code

After the code is executed, if the installation is successful, the result value obtained is "PKG:/data/local/tmp/calculator.apk \ nsuccess". If the installation fails, there is no ending "success ".

The installation code is ready. Now we will introduce the first method to build your own APK into the Rom. The premise is that your phone has been flushed and retains the recovery-windows.bat/recover-linux.sh file.

The specific steps for HTC-legend are as follows:

1. Connect the USB to your device and enter "ADB reboot recovery" in the command line. After the device restarts, a red triangle and arrow icon are displayed.

2. (under PC) Go To Your fl folder and run './recover-linux.sh', the screen will display a green menu

3. If the result is "error: device not found", run "./ADB-Linux kill-server" and then run './recovery-linux.sh' again until the green menu is displayed.

4. Run "ADB shell Mount/dev/block/mtdblock3/system". Now, you can write to/system.

5. Run the command ADB push <your_apk_path>/system/<your_apk_name> on the PC. So far, the built-in operation is successful.

In the second method, you need to first create an unsigned APK package and then sign it with the system signature. I have explained this in my previous blog post, so I won't repeat it here. [Android] use the platform key to sign the APK File

Since HTC-legend is "original", the silent installation is smooth. However, some moto or happy phone phones are generally not supported.

Related Article

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.