Android Programming implements monitoring apk installation, uninstall, and replacement methods _android

Source: Internet
Author: User

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.

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.