This article describes the Android programming implementation of monitoring APK installation, uninstall, and replacement methods. Share to everyone for your reference, specific as follows:
public class Getbroadcast extends Broadcastreceiver {private static Getbroadcast Mreceiver = new Getbroadcast ();
private static Intentfilter Mintentfilter;
public static void Registerreceiver {mintentfilter = new intentfilter ();
Mintentfilter.adddatascheme ("package");
Mintentfilter.addaction (intent.action_package_added);
Mintentfilter.addaction (intent.action_package_removed);
Mintentfilter.addaction (intent.action_package_replaced);
Context.registerreceiver (Mreceiver, Mintentfilter);
public static void Unregisterreceiver {Context.unregisterreceiver (mreceiver);
@Override public void OnReceive (context context, Intent Intent) {String action = intent.getaction ();
if (Intent.ACTION_PACKAGE_ADDED.equals (ACTION)) {Toast.maketext (context, "has application added", Toast.length_long). Show (); else if (Intent.ACTION_PACKAGE_REMOVED.equals (ACTION)) {Toast.maketext (context, "has application deleted", Toast.length_long). Show (); }/* Else if (Intent.ACTION_PACKAGE_CHANGED.equals (ACTION)) {* Toast.maketext (context, "have application Changed", Toast.length _long). Show (); } */Else if (Intent.ACTION_PACKAGE_REPLACED.equals (ACTION)) {Toast.maketext (context, "have application replaced", Toast.lengt
H_long). Show (); }/* Else if (Intent.ACTION_PACKAGE_RESTARTED.equals (ACTION)) {* Toast.maketext (context, "has application restarted", Toast.leng Th_long). Show (); }/* * else if (Intent.ACTION_PACKAGE_INSTALL.equals (ACTION)) {* Toast.maketext (context, "have application Installed", Toast . Length_long). Show ();
}
*/
}
}
I hope this article will help you with your Android programming.