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

2018-07-20    来源:open-open

容器云强势上线!快速搭建集群,上万Linux镜像随意使用
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(); }
 
*/
 
}
 
}


标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

上一篇:java编写的FTP上传简单工具类

下一篇:Android的Px与Dp转化工具类