欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android编程实现监控apk安装,卸载,替换的方法

程序员文章站 2024-02-14 10:56:46
本文实例讲述了android编程实现监控apk安装,卸载,替换的方法。分享给大家供大家参考,具体如下: public class getbroadcast ext...

本文实例讲述了android编程实现监控apk安装,卸载,替换的方法。分享给大家供大家参考,具体如下:

public class getbroadcast extends broadcastreceiver {
  private static getbroadcast mreceiver = new getbroadcast();
  private static intentfilter mintentfilter;
  public static void registerreceiver(context context) {
    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 context) {
    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, "有应用被添加", toast.length_long).show();
    } else if (intent.action_package_removed.equals(action)) {
      toast.maketext(context, "有应用被删除", toast.length_long).show();
    }
    /*
    * else if(intent.action_package_changed.equals(action)){
    * toast.maketext(context, "有应用被改变", toast.length_long).show(); }
    */
    else if (intent.action_package_replaced.equals(action)) {
      toast.maketext(context, "有应用被替换", toast.length_long).show();
    }
    /*
    * else if(intent.action_package_restarted.equals(action)){
    * toast.maketext(context, "有应用被重启", toast.length_long).show(); }
    */
    /*
    * else if(intent.action_package_install.equals(action)){
    * toast.maketext(context, "有应用被安装", toast.length_long).show(); }
    */
  }
}

希望本文所述对大家android程序设计有所帮助。