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?


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">
    <action android:name="android.intent.action.BOOT_COMPLETED" />



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
mBroadcastMgr.registerReceiver(receiver, intentFilter);




All Articles