Dynamic registration of BroadcastReceiver actions (intent filter)
I have a BroadcastReceiver application and a service in my application. I get information about actions in a service from an action. I have to register this action dynamically with the receiver. I have several actions defined in AndroidManifest.xml, but this action needs to be defined dynamically. Can someone please help me with this?
Thank.
PS Example of receiver tag from AndroidManifest.xml. BOOT_COMPLETED is one of the actions I'm talking about. I get this information from this service.
<receiver android:name="com.test.TestReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
+3
source to share
1 answer
You can use this:
IntentFilter intentFilter = new IntentFilter("android.intent.action.BOOT_COMPLETED");
YourReceiver receiver = new YourReceiver();
LocalBroadcastManager mBroadcastMgr = LocalBroadcastManager
.getInstance(getApplicationContext());
mBroadcastMgr.registerReceiver(receiver, intentFilter);
0
source to share