Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android BroadcastReceiver without intent filters

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?

like image 285
Sebastian Nowak Avatar asked Aug 10 '12 11:08

Sebastian Nowak


1 Answers

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

like image 129
Chris Avatar answered Sep 18 '22 21:09

Chris