1. Manifest에 receiver등록
<receiver android:name=".IntentReceiver">
<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>
2. Receiver class구현
public class IntentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("_PACKAGE_OBSERVER_", "intent : ");
Log.d("_PACKAGE_OBSERVER_", " action = " + intent.getAction());
Log.d("_PACKAGE_OBSERVER_", " data = " + intent.getData());
}
}
위와 같이 하면 data에 package명을 확인하여 어떤 패키지가 추가되거나 삭제되었는지 알 수 있다.