Android编程实现监控apk安装,卸载,替换的方法
程序员文章站
2023-12-19 22:16:34
本文实例讲述了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程序设计有所帮助。