Android 代码监控apk安装,卸载,替换

 
01   public class GetBroadcast extends BroadcastReceiver {
02   
03   private static GetBroadcast mReceiver = new GetBroadcast();
04   
05   private static IntentFilter mIntentFilter;
06   
07   public static void registerReceiver(Context context) {
08   
09   mIntentFilter = new IntentFilter();
10   
11   mIntentFilter.addDataScheme("package");
12   
13   mIntentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
14   
15   mIntentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
16   
17   mIntentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
18   
19   context.registerReceiver(mReceiver, mIntentFilter);
20   
21   }
22   
23   public static void unregisterReceiver(Context context) {
24   
25   context.unregisterReceiver(mReceiver);
26   
27   }
28   
29   @Override
30   
31   public void onReceive(Context context, Intent intent) {
32   
33   String action = intent.getAction();
34   
35   if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
36   
37   Toast.makeText(context, "有应用被添加", Toast.LENGTH_LONG).show();
38   
39   } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
40   
41   Toast.makeText(context, "有应用被删除", Toast.LENGTH_LONG).show();
42   
43   }
44   
45   /*
46   
47   * else if(Intent.ACTION_PACKAGE_CHANGED.equals(action)){
48   
49   * Toast.makeText(context, "有应用被改变", Toast.LENGTH_LONG).show(); }
50   
51   */
52   
53   else if (Intent.ACTION_PACKAGE_REPLACED.equals(action)) {
54   
55   Toast.makeText(context, "有应用被替换", Toast.LENGTH_LONG).show();
56   
57   }
58   
59   /*
60   
61   * else if(Intent.ACTION_PACKAGE_RESTARTED.equals(action)){
62   
63   * Toast.makeText(context, "有应用被重启", Toast.LENGTH_LONG).show(); }
64   
65   */
66   
67   /*
68   
69   * else if(Intent.ACTION_PACKAGE_INSTALL.equals(action)){
70   
71   * Toast.makeText(context, "有应用被安装", Toast.LENGTH_LONG).show(); }
72   
73   */
74   
75   }
76   
77   }

你可能感兴趣的:(Android 代码监控apk安装,卸载,替换)