Android BroadcastReceiver with no intent-filter

android

I've come across something like this in the AndroidManifest.xml:

<receiver android:name="com.testco.test.TestReceiver"/>

The above is TestReceiver extends the BroadcastReceiver class. I thought the receiver will receive all intents but apparently it doesn't, and it doesn't work unless I add intent-filter tags in it. So what does it do if it has no intent-filter? Is it a typo or does it really do something?

UPDATE: I figured this out with the help of this link Trying to have a Broadcast Receiver with No filter

Instead of calling a broadcast with the usual String identifier, you can set an action string to the intent, then broadcast it. Sample code for reference:

Intent notifyIntent = new Intent(getApplicationContext(), TestReceiver.class);
notifyIntent.setAction("RECEIVE");
sendBroadcast(notifyIntent);

The handling at the BroadcastReceiver is the same.

Best Answer

An Intent filter is needed in case of implicit intents, and if an intent filter is not specified, it must be invoked explicitly. So to invoke this receiver you would need to invoke:

Intent intent = new Intent(getApplicationContext(), com.testco.test.TestReceiver.class);
sendBroadcast(intent);`