Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BroadcatReceiver declared in manifest.xml not receiving LocalBroadcastManager intents

While it is possible to declare a 'Local' BroadcastReceiver via code so it receives intents published via a LocalBroadcastManager.Ex

LocalBroadcastManager.getInstance(this).registerReceiver(new FooReceiver(), new IntentFilter("foo_intent_filter"));

I wonder if it is possible to declare such receiver via the manifest.xml (cleaner) .

When I use the 'manifest way', the receiver is not 'receiving' the intents.

  <receiver
        android:name="FooReceiver"
        android:enabled="true"
        android:exported="false" >
        <intent-filter>
            <action android:name="foo_intent_filter" />
        </intent-filter>
  </receiver>

Am I missing something? or the code-way is the only viable solution.

Thanks

like image 540
Jesus Monzon Legido Avatar asked Jun 06 '14 12:06

Jesus Monzon Legido


1 Answers

I wonder if it is possible to declare such receiver via the manifest.xml (cleaner) .

First, that is not possible.

Second, registering in the manifest has little to do with it being "cleaner". It is to allow Android to instantiate the receiver on its own, so that you can respond to broadcasts when your process is not running. And, in the specific example that you cite, it is to allow any app on the system to send you a broadcast. Neither of those are relevant for LocalBroadcastManager.

like image 150
CommonsWare Avatar answered Oct 31 '22 15:10

CommonsWare