[Android] Two Methods for installing APK silently

Source: Internet
Author: User

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. However, after reading this article, I will still disappoint some people.

Android considers all permission based on its potential risks (the property name is protectionlevel

) Is divided into four levels, that is"normal
",

"dangerous
",

"signature
",

"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 grants onlyApplications that are in the Android system image
 
Or
 
That areSigned with the same certificates as those in the system image.
Please avoid using this option, assignature
 
Protection Level shoshould be sufficient for most needs and works regardless of exactly where applications are installed."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 compile the code for directly installing APK. Here, we use the PM install <apk_path> command instead of the complicated undisclosed packagemanager. install () method.

String [] ARGs = {"PM", "Install", "-R", apkabsolutepath}; <br/> string result = ""; <br/> processbuilder = new processbuilder (ARGs); <br/> Process = NULL; <br/> inputstream erris = NULL; <br/> inputstream inis = NULL; <br/> try {<br/> bytearrayoutputstream baos = new bytearrayoutputstream (); <br/> int READ =-1; <br/> process = processbuilder. start (); <br/> erris = process. geterrors Tream (); <br/> while (read = erris. Read ())! =-1) {<br/> baos. write (read); <br/>}< br/> baos. write ('/N'); <br/> inis = process. getinputstream (); <br/> while (read = inis. read ())! =-1) {<br/> baos. write (read); <br/>}< br/> byte [] DATA = baos. tobytearray (); <br/> result = new string (data); <br/>}catch (ioexception e) {<br/> E. printstacktrace (); <br/>}catch (exception e) {<br/> E. printstacktrace (); <br/>}finally {<br/> try {<br/> If (erris! = NULL) {<br/> erris. Close (); <br/>}< br/> If (INIS! = NULL) {<br/> inis. close (); <br/>}< br/>} catch (ioexception e) {<br/> E. printstacktrace (); <br/>}< br/> If (process! = NULL) {<br/> process. Destroy (); <br/>}< br/> return result; <br/>}

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 kept the recovery-windows.bat/recover-linux.sh

File.

The specific steps for HTC-legend are as follows:

1. Connect your device with USB and enter
"ADB reboot recovery"
The host restarts. A red triangle and arrow icon are displayed after startup.

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"
Then run again
'./Recovery-linux.sh'
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.



The above two methods both declare Android. Permission. install_packages in androidmanifest, And the strange thing is that the"

Int result = checkcallingorselfpermission (intent. action_package_install)

", The result value is Android. content. PM. packagemanager. permission_denied instead of permission_granted.

 

OK. You have finished speaking. Go to bed.

 

This article belongs to the csdn blog master.Sodino
All

Reprinted please indicate the source: http://blog.csdn.net/sodino/archive/2011/03/10/6238818.aspx

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.