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