As we displayed in the previous example, we can receive broadcasts in one of the two following ways:
- Registering the broadcast receiver through Android Manifest
- Registering the broadcast using the registerBroadcast() method in the contexts
Declaring through Manifest requires the following:
- The <receiver> element with android:name and android:exported parameters.
- The receiver must contain intent filters for the actions we subscribe. Take a look at the following example:
<receiver android:name=".OurBootReceiver" android:exported="true"> <intent-filter> <action android:name= "android.intent.action.BOOT_COMPLETED"/> ... <action android:name="..."/> <action android:name="..."/> <action android:name="..."/> </intent-filter> ...