<receiver android:name="com.itheima.appslistener.AppsReceiver">
<intent-filter >
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REPLACED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
第三步,重写广播接受者中OnReceiver方法:
public void onReceive(Context context, Intent intent) {
//判断收到的是什么广播
String action = intent.getAction();
//获取安装更新卸载的是什么应用
Uri uri = intent.getData();
if(Intent.ACTION_PACKAGE_ADDED.equals(action)){
Toast.makeText(context, uri + "被安装了", 0).show();
}
else if(Intent.ACTION_PACKAGE_REMOVED.equals(action)){
Toast.makeText(context, uri + "被删除了", 0).show();
}
else if(Intent.ACTION_PACKAGE_REPLACED.equals(action)){
Toast.makeText(context, uri + "被更新了", 0).show();
}
}