Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get intent filter for receivers

I am trying to get a list of receivers that handle android.intent.action.BOOT_COMPLETED for other applications.

I can get only the apps with that action with this:

final PackageManager pm = getPackageManager();
final Intent intent = new Intent("android.intent.action.BOOT_COMPLETED");
final List<ResolveInfo> activities = pm.queryBroadcastReceivers(intent, 0);
for (ResolveInfo ri : activities) {
    Log.i(TAG, "app name: " + ri.loadLabel(pm));
}

I can get a list of receivers with this code:

final List<PackageInfo> packs = pm.getInstalledPackages(PackageManager.GET_RECEIVERS);
for (final PackageInfo p : packs) {
    ActivityInfo[] receivers = p.receivers;
    if (receivers != null) {
        for (ActivityInfo ai : receivers) {
            Log.i(TAG, "receiver: " + ai.name);
        }
    }                   
}

After I get the receivers I cannot tell what the intent-filter/action is. If an app has two receivers I need to know which one handles android.intent.action.BOOT_COMPLETED. Is there a way I can get this info?

like image 889
Jared Rummler Avatar asked Nov 15 '11 20:11

Jared Rummler


Video Answer


1 Answers

I reformatted for people. Use this and thanks for question.

PackageManager packageManager = getPackageManager();
List<String> startupApps = new ArrayList<String>();
Intent intent = new Intent(Intent.ACTION_BOOT_COMPLETED);
List<ResolveInfo> activities = packageManager.queryBroadcastReceivers(intent, 0);
for (ResolveInfo resolveInfo : activities) {
    ActivityInfo activityInfo = resolveInfo.activityInfo;
    if (activityInfo != null) {
        startupApps.add(activityInfo.name);
    }
}
like image 112
Ravi Patel Avatar answered Sep 19 '22 16:09

Ravi Patel