Android监控apk安装,卸载,替换 Android编程实现监控apk安装,卸载,替换的方法
hshm20517 人气:0想了解Android编程实现监控apk安装,卸载,替换的方法的相关内容吗,hshm20517在本文为您仔细讲解Android监控apk安装,卸载,替换的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Android,监控,apk,Android监控apk安装,Android监控apk卸载,Android监控apk替换,下面大家一起来学习吧。
本文实例讲述了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程序设计有所帮助。
加载全部内容