Alex Rivera | Logout

Trying to have a Broadcast Receiver with No filter

Asked 2012-01-13T23:35:03.057
8
IntentFilter intentFilter = new IntentFilter("test");
registerReceiver(mReceiver, intentFilter);

I would like to have no filter like registerReceiver(mReceiver, null) but my app crashes as a result of that. Can I have new IntentFiler() as an empty filer?

Edit
Report

1 Answer

10

Because the BroadcastReceiver returns null when there is no match via the criteria from the IntentFilter, it is not possible with the API to accomplish what you hope to accomplish (which I'm assuming is sending any and all Broadcasts to mReceiver).

You can certainly specify an empty IntentFilter, but this will be pretty useless as registering the receiver won't cause it to catch any broadcasts (unless they are directly targeted to the receiver, as mentioned by MisterSquonk in the comments). Otherwise you must know exactly which broadcasts you want to catch with your BroadcastReceiver, then specify the criteria in the IntentFilter.

answered 2012-01-13T23:43:14.523

Your Answer