I saw in few android ad networks sdks that they are declaring BroadcastReceiver
with no intent filters. Something like this:
<receiver android:name="com.example.SampleReceiver" />
My guess is that such receiver would capture all possible events. So I've tried doing it myself and created a SampleReceiver
:
public class SampleReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
System.out.println("Event captured: " + intent.getAction());
}
}
I've launched the app, tried to fire some events by doing various action on my phone and noticed that onReceive()
wasn't called even once.
So the question is - how does such BroadcastReceiver without intent filters work? Maybe it require the intent filters to be created via code? If so, how? If not, then why isn't it receiving any events? What's going on here?
If you do not have some intent filters, the only way to receive something is to call the receiver explicitly. This would look like this:
context.sendBroadcast(new Intent(context, MyBroadcastReceiverClass.class));
Another guy already answered this question in the following post: https://stackoverflow.com/questions/10051256/broadcast-receiver-not-receiving
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With