Android monitoring program installation and deletion implementation

Source: Internet
Author: User

This article mainly discusses how to monitor the installation and deletion of Android packages.

 

 

The Installation Method of the Android system has been described in detail in "detailed investigation of Android application installation methods". The link is as follows:

Http://blog.csdn.net/Zengyangtech/archive/2010/07/15/5737522.aspx

 

 

Based on these installation methods, how can we monitor system installation?

 

By reading the description in the intent. Action section of the android SDK, we can find some System Broadcasts related to the package.

Android. intent. action. package_added <br/> android. intent. action. package_changed <br/> android. intent. action. package_data_cleared <br/> android. intent. action. package_install <br/> android. intent. action. package_removed <br/> android. intent. action. package_replaced <br/> android. intent. action. package_restarted 

Where

Action_package_added

The description in the SDK is

Broadcast Action: A new application package has been installed on the device.

Action_package_removed

The description in the SDK is

Broadcast action: an existing application package has been removed from the device.

Action_package_replaced

The description in the SDK is

Broadcast action: a new version of an application package has been installed, replacing an existing version that was previusly installed.

 

With these three broadcast messages, we can monitor the installation and deletion of Android applications.

 

The detailed implementation code is as follows:

Getbroadcast. Java

<Br/> package ZY. broadcast; <br/> Import android. content. broadcastreceiver; <br/> Import android. content. context; <br/> Import android. content. intent; <br/> Import android. widget. toast; <br/> public class getbroadcast extends broadcastreceiver {<br/> @ override <br/> Public void onreceive (context, intent) {</P> <p> If (intent. action_package_added.equals (intent. getaction () {<br/> toast. maketext (context, "added applications", toast. length_long ). show (); <br/>}< br/> else if (intent. action_package_removed.equals (intent. getaction () {<br/> toast. maketext (context, "an application has been deleted", toast. length_long ). show (); <br/>}< br/>/* else if (intent. action_package_changed.equals (intent. getaction () {<br/> toast. maketext (context, "Application changed", toast. length_long ). show (); <br/>}*/<br/> else if (intent. action_package_replaced.equals (intent. getaction () {<br/> toast. maketext (context, "application replaced", toast. length_long ). show (); <br/>}< br/>/* else if (intent. action_package_restarted.equals (intent. getaction () {<br/> toast. maketext (context, "an application has been restarted", toast. length_long ). show (); <br/>}*/<br/>/* else if (intent. action_package_install.equals (intent. getaction () {<br/> toast. maketext (context, "an application is installed", toast. length_long ). show (); <br/>}*/</P> <p >}</P> <p>} 

Then, the <intent-filter> of these actions can be declared in androidmanifest. XML to capture these broadcast messages in the system.

The specific source code is as follows:

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <manifest xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> package = "ZY. broadcast "<br/> Android: versioncode =" 1 "<br/> Android: versionname =" 1.0 "> <br/> <application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name"> <br/> <activity Android: Name = ". broadcast "<br/> Android: Label =" @ string/app_name "> <br/> <intent-filter> <br/> <action Android: Name =" android. intent. acti On. main "/> <br/> <category Android: Name =" android. intent. category. launcher "/> <br/> </intent-filter> <br/> </activity> <br/> <receiver er Android: Name =" getbroadcast "Android: enabled = "true"> <br/> <intent-filter> <br/> <action Android: Name = "android. intent. action. package_added "> </Action> <br/> <! -- <Action Android: Name = "android. intent. action. package_changed "> </Action> --> <br/> <action Android: Name =" android. intent. action. package_removed "> </Action> <br/> <action Android: Name =" android. intent. action. package_replaced "> </Action> <br/> <! -- <Action Android: Name = "android. Intent. Action. package_restarted"> </Action> --> <br/> <! -- <Action Android: Name = "android. intent. action. package_install "> </Action> --> <br/> <data Android: scheme = "package"> </data> <br/> </intent-filter> <br/> </javaser> <br/> </Application> <br/> <uses-SDK Android: minsdkversion = "7"/> </P> <p> </manifest> 

 

 

After the program is installed, the system registers the broadcastreceiver

The toast prompt is displayed when an application is installed, deleted, or replaced.

 

Delete An Application

 

Add Application

 

Application replaced

 

 

In this way, we can monitor the installation process of Android applications.

 

As for the interception of the installation process, I am also working on it. You can have a good idea with me

Share, thank you

 

 

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.