[Android] Android listens to apk installation and replacement to uninstall Broadcast

Source: Internet
Author: User

[Android] Android listens to apk installation and replacement to uninstall Broadcast

First, you need to obtain the application installation status, in the form of Broadcast

The following are application-related Broadcast actions:

ACTION_PACKAGE_ADDED a new application package has been installed on the device, and the data includes the package name (this broadcast cannot be received by the latest package Program)
ACTION_PACKAGE_REPLACED install a new version of the application to the device and replace the existing version.
ACTION_PACKAGE_CHANGED an existing application package, including the package name
ACTION_PACKAGE_REMOVED an existing application package has been removed from the device, including the package name (this broadcast cannot be received by the package program being installed)
The ACTION_PACKAGE_RESTARTED user restarts a package, and all processes in the package will be killed. All running time States associated with the package should be removed, including the package name (the package re-start program cannot receive this broadcast)
The ACTION_PACKAGE_DATA_CLEARED user knows the data of a package, including the package name (the package clearing program cannot receive this broadcast)

Code Implementation

Define broadcast in AndroidManifest. xml

<receiver android:name==>            <intent-filter>                <action android:name= />                 <action android:name= />                <action android:name= />                <data android:scheme= />            </intent-filter>        </receiver>

Here we use

ACTION_PACKAGE_ADDED a new application package has been installed on the device, and the data includes the package name (this broadcast cannot be received by the latest package Program)
ACTION_PACKAGE_REPLACED install a new version of the application to the device and replace the existing version.
ACTION_PACKAGE_REMOVED an existing application package has been removed from the device, including the package name (this broadcast cannot be received by the package program being installed)

Let's look at AppInstallReceiver.

AppInstallReceiver = "installed successfully" + = "uninstalled successfully" + = "replaced successfully" +

The code implementation is relatively simple. Based on the received Action, determine whether the application is installed, uninstalled, or replaced with another version.

 

//////////////////////////////////////// //////

Reprinted original statement, please note

This article is from Ray-Ray's blog

Document address http://www.cnblogs.com/rayray/p/3178403.html

Thank you for your recommendation and favorites.

Your support! Our motivation!

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.