天天看點

Android 代碼監控apk安裝,解除安裝,替換

java代碼

  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(); }

繼續閱讀