Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

queryBroadcastReceivers does not find receivers registered with registerReceiver

I need to find out which broadcast receivers can handle a given Intent.

It seems that queryBroadcastReceivers() does not return receivers registered in code using registerReceiver() but only receivers declared in AndroidManifest.xml.

Is this behavior by design?

Any other way to find all installed receivers for some Intent ?

Thanks.

like image 572
Assaf Avatar asked Oct 05 '10 09:10

Assaf


2 Answers

It looks like it's not possible to detect receivers registered in code, as per this recent message on the mailing list: http://groups.google.com/group/android-developers/msg/5fd1cdb24b2a6760

This is disappointing as I was looking for a way to do the same thing.

like image 172
Matt Hall Avatar answered Jan 04 '23 05:01

Matt Hall


If the receivers you're interested in are yours, you can use sendOrderedBroadcast instead of regular broadcast.

This makes the broadcast goes to all registered receivers one by one, according to priority, and finally to your supplied broadcast receiver, which according to the result/data passed to it, can figure out which receivers handled this before it.

You can check this example project which uses this method: http://www.mannaz.at/codebase/android-activity-foreground-surveillance/

like image 41
marmor Avatar answered Jan 04 '23 05:01

marmor