The first is to obtain the installation state of the application by broadcasting the form
The following is an application-related broadcast Action
action_package_added A new application package is already installed on the device and the data includes the package name (the latest installed package program cannot receive this broadcast)
action_package_replaced A new version of the application is installed to the device, replacing the previously existing version
action_package_changed An existing application package has been changed, including the package name
action_package_removed An existing application package has been removed from the device, including the package name (the package program being installed cannot receive this broadcast)
action_package_restarted users to restart a package, all processes of the package will be killed, all the running time status associated with it should be removed, including the package name (restart package cannot receive this broadcast)
action_package_data_cleared users already know a packet's data, including the package name (the removal package does not receive this broadcast)
Code Implementation
define a broadcast in Androidmanifest.xml
Copy Code code as follows:
<receiver android:name= ". Appinstallreceiver "
android:label= "@string/app_name" >
<intent-filter>
<action android:name= "Android.intent.action.PACKAGE_ADDED"/>
<action android:name= "Android.intent.action.PACKAGE_REPLACED"/>
<action android:name= "Android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme= "package"/>
</intent-filter>
</receiver>
Here is a selection of
action_package_added A new application package is already installed on the device and the data includes the package name (the latest installed package program cannot receive this broadcast)
action_package_replaced A new version of the application is installed to the device, replacing the previously existing version
action_package_removed An existing application package has been removed from the device, including the package name (the package program being installed cannot receive this broadcast)
And look at Appinstallreceiver.
Copy Code code as follows:
public class Appinstallreceiver extends Broadcastreceiver {
@Override
public void OnReceive (context context, Intent Intent) {
Packagemanager manager = Context.getpackagemanager ();
if (intent.getaction (). Equals (intent.action_package_added)) {
String PackageName = Intent.getdata (). Getschemespecificpart ();
Toast.maketext (Context, "installed successfully" +packagename, Toast.length_long). Show ();
}
if (intent.getaction (). Equals (intent.action_package_removed)) {
String PackageName = Intent.getdata (). Getschemespecificpart ();
Toast.maketext (Context, "Uninstall Success" +packagename, Toast.length_long). Show ();
}
if (intent.getaction (). Equals (intent.action_package_replaced)) {
String PackageName = Intent.getdata (). Getschemespecificpart ();
Toast.maketext (Context, "replace success" +packagename, Toast.length_long). Show ();
}
}
}
Code implementation is relatively simple, based on the received action to determine whether the application is an loading or unloading or replaced by another version