3c71
3c71

Reputation: 4511

queryBroadcastReceivers with PACKAGE_REPLACED

The following code returns an empty list, whereas the app running it has this particular intent registered!?

pm.queryBroadcastReceivers(new Intent(Intent.PACKAGE_REPLACED), PackageManager.GET_INTENT_FILTERS | PackageManager.GET_DISABLED_COMPONENTS);

Is there a way to retrieve all receivers for such intent and other similar ones?

This method seems very unreliable or did I do something wrong?

Thanks.

Upvotes: 1

Views: 3206

Answers (2)

赵陈红
赵陈红

Reputation: 1

can get info use code like

List<String> startupApps = new ArrayList<String>();
Intent intent = new Intent(Intent.ACTION_PACKAGE_ADDED);
Uri uriInfo = Uri.parse("package://");
intent.setData(uriInfo);
final List<ResolveInfo> activities = packageManager
                .queryBroadcastReceivers(intent, 0);
for (ResolveInfo resolveInfo : activities) {
        ActivityInfo activityInfo = resolveInfo.activityInfo;
        if (activityInfo != null)
            startupApps.add(activityInfo.name);
}

Upvotes: 0

3c71
3c71

Reputation: 4511

After much research, only the source code here provided some insights on this:

When only specifying an action in the intent, the API will filter for all receivers that accepts such action without any data type or scheme.

Turns out many action intents require a scheme or data type, such as the 'package' scheme on any PACKAGE_* actions.

So the intent needs to specify the "package" scheme.

Upvotes: 2

Related Questions