查詢某個Action會由哪些BroadcastReceivers接收

開個新的APP把下面這段code放進去,然後可以在onCreate或者onResume呼叫看看

    public boolean isIntentAvailable(String action) {
        Log.d(TAG, "isIntentAvailable()");
        if (action ==null) action = Intent.ACTION_BOOT_COMPLETED;
        final PackageManager packageManager = getApplicationContext().getPackageManager();
        final Intent intent = new Intent(action);
        List resolveInfo = null;
        resolveInfo = packageManager.queryBroadcastReceivers(intent, 0);
        //List resolveInfo = packageManager.queryIntentActivities(intent, PackageManager.0);
        if (resolveInfo.size()<=0) {
            Log.d(TAG, "info is empty, try another option " + resolveInfo.size());
            resolveInfo = packageManager.queryBroadcastReceivers(intent, PackageManager.MATCH_DEFAULT_ONLY);
        }
        Log.d(TAG, "queryBroadcastReceivers(action={" + action + "}) info len=" + resolveInfo.size());
        if (resolveInfo.size() > 0) {
            for (ResolveInfo info : resolveInfo) {
                Log.d(TAG, "info content={" + info.toString() + "}");
            }
            return true;
        }
        return false;
    }
執行結果:
02-04 14:00:36.682 D/TestAPP( 7267): isIntentAvailable()
02-04 14:00:36.698 D/TestAPP( 7267): queryBroadcastReceivers(action={android.intent.action.BOOT_COMPLETED}) info len=17
02-04 14:00:36.699 D/TestAPP( 7267): info content={ResolveInfo{1d0bfa0f android/com.android.server.BootReceiver p=1000 m=0x108000}}
02-04 14:00:36.699 D/TestAPP( 7267): info content={ResolveInfo{3ae43a9c com.android.systemui/.BootReceiver p=1000 m=0x108000}}
02-04 14:00:36.699 D/TestAPP( 7267): info content={ResolveInfo{db0aca5 com.android.providers.calendar/.CalendarReceiver m=0x108000}}
02-04 14:00:36.700 D/TestAPP( 7267): info content={ResolveInfo{1571f87a com.droidlogic.mediacenter/.DMRBroadcastReceiver m=0x108000}}
02-04 14:00:36.700 D/TestAPP( 7267): info content={ResolveInfo{398282b com.android.providers.downloads/.DownloadReceiver m=0x108000}}
02-04 14:00:36.700 D/TestAPP( 7267): info content={ResolveInfo{20486488 com.android.managedprovisioning/.BootReminder m=0x108000}}
02-04 14:00:36.700 D/TestAPP( 7267): info content={ResolveInfo{16a46e21 com.android.providers.media/.MediaScannerReceiver m=0x108000}}
02-04 14:00:36.701 D/TestAPP( 7267): info content={ResolveInfo{c172246 com.android.providers.media/.MtpReceiver m=0x108000}}
02-04 14:00:36.701 D/TestAPP( 7267): info content={ResolveInfo{3a6f1c07 com.android.onetimeinitializer/.OneTimeInitializerReceiver m=0x108000}}
02-04 14:00:36.701 D/TestAPP( 7267): info content={ResolveInfo{30434134 com.android.tv.settings/.users.UserSwitchListenerService$BootReceiver m=0x108000}}
02-04 14:00:36.701 D/TestAPP( 7267): info content={ResolveInfo{2cb8cb5d com.droidlogic/.BootComplete m=0x108000}}
02-04 14:00:36.701 D/TestAPP( 7267): info content={ResolveInfo{3f931cd2 com.android.deskclock/.AlarmInitReceiver m=0x108000}}
02-04 14:00:36.702 D/TestAPP( 7267): info content={ResolveInfo{d771a3 com.android.inputmethod.latin/.SystemBroadcastReceiver m=0x108000}}
02-04 14:00:36.702 D/TestAPP( 7267): info content={ResolveInfo{76d3ca0 com.droidlogic.otaupgrade/.LoaderReceiver m=0x108000}}
02-04 14:00:36.702 D/TestAPP( 7267): info content={ResolveInfo{35bbc059 com.droidlogic.PPPoE/.PppoeBroadcastReceiver m=0x108000}}
02-04 14:00:36.702 D/TestAPP( 7267): info content={ResolveInfo{3362341e com.droidlogic.service.remotecontrol/.RCServiceReceiver m=0x108000}}
02-04 14:00:36.703 D/TestAPP( 7267): info content={ResolveInfo{39e584ff com.droidlogic.SubTitleService/.SubTitleServiceBroadcastReceiver m=0x108000}}

留言