主要为:
Intent.ACTION_PACKAGE_INSTALL:安装
Intent.ACTION_PACKAGE_ADDED:添加
Intent.ACTION_PACKAGE_REPLACED:替换
Intent.ACTION_PACKAGE_REMOVED:卸载
Intent.ACTION_PACKAGE_CHANGED:改变
Intent.ACTION_PACKAGE_RESTARTED:重启
第一步:定义广播(外部类)
public class BootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
} else if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) { } else if (Intent.ACTION_PACKAGE_CHANGED.equals(intent.getAction())) { } else if (Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())) { } else if (Intent.ACTION_PACKAGE_RESTARTED.equals(intent.getAction())) { } else if (Intent.ACTION_PACKAGE_INSTALL.equals(intent.getAction())) { } else { } } }第二步:注册广播----静态注册(注意action不可改变)
<receiver android:name="com.receiver.BootReceiver"> <intent-filter> <action android:name="android.intent.action.PACKAGE_ADDED" /> <action android:name="android.intent.action.PACKAGE_REMOVED" /> <action android:name="android.intent.action.PACKAGE_CHANGED" /> <action android:name="android.intent.action.PACKAGE_REPLACED" /> <action android:name="android.intent.action.PACKAGE_RESTARTED" /> <action android:name="android.intent.action.PACKAGE_INSTALL" /> <data android:scheme="package" /> </intent-filter> </receiver>