BroadcatReceiver declared in manifest.xml without getting LocalBroadcastManager intent

Although you can declare "Local" BroadcastReceiver through code so that it receives intentions published through LocalBroadcastManager.Ex

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

I wonder if such a receiver can be declared using the .xml manifest (cleaner).

When I use the "manifest method", the receiver does not accept intentions.

  <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 path code is the only viable solution.

thanks

+7
android broadcastreceiver
source share
1 answer

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

Firstly, it is impossible.

Secondly, registration in the manifest has little to do with the fact that it is β€œcleaner”. This allows Android to create a receiver on its own so that you can respond to broadcasts when your process is not running. And in the specific example that you are quoting, this allows any application in the system to send you a broadcast. None of them apply to LocalBroadcastManager .

+5
source share

All Articles