BroadcastReceiver
を使用して登録できますIntent.ACTION_PACKAGE_ADDED
( Intent.ACTION_PACKAGE_REMOVED
および/またはIntent.ACTION_PACKAGE_CHANGED
必要に応じて)。例えば、
void registerReceiver() {
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
filter.addDataScheme("package_name");
}
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(Intent.ACTION_PACKAGE_ADDED)) {
Uri data = intent.getData();
String pkgName = data.getEncodedSchemeSpecificPart();
}
/* etc. */
}