How to manage what broadcasts Broadcast Receivers receive in Kotlin
A guide that explains how to allow Android broadcast receivers to listen to or ignore broadcasts from other apps.
Approximately 17.35 minutes in.
As discussed at Google I/O 2023, registering receivers with intention using the RECEIVER_EXPORTED / RECEIVER_NOT_EXPORTED flag was introduced as part of Android 13 and is now a requirement for apps running on Android 14 or higher (U+).
If you do not implement this, the system will throw a security exception.
I want the receiver to listens to broadcasts from other apps
To allow the broadcast receiver to receive broadcasts from other apps, register the receiver using the following code:
context.registerReceiver (broadcastReceiver, intentFilter, RECEIVER_EXPORTED);
I do not want the receiver to listens to broadcasts from other apps
To register a broadcast receiver that does not receive broadcasts from other apps, including system apps, register the receiver using the following code:
context.registerReceiver (broadcastReceiver, intentFilter, RECEIVER_NOT_EXPORTED);