public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if ("android.intent.action.PACKAGE_REMOVED".equals(action)) { System.out.println("卸载了应用程序:"+intent.getData().toString()); }else if ("android.intent.action.PACKAGE_ADDED".equals(action)) { System.out.println("安装了应用程序:"+intent.getData().toString()); } }
清单文件: <receiver android:name="com.example.add_remove.AddRemoveReceiver" > <intent-filter > <action android:name="android.intent.action.PACKAGE_ADDED"/> <action android:name="android.intent.action.PACKAGE_REMOVED"/> <data android:scheme="package"/> </intent-filter> </receiver>