one of receiver exported or receiver not exported should be specified when a receiver isn't being registered exclusively for system broadcasts

7 hours ago 3
Nature

Starting from Android 13 and becoming mandatory in Android 14, when you register a broadcast receiver programmatically (not just declare it in the manifest), you must specify either the flag RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED. This change is related to tightened security requirements around broadcast receivers.

  • RECEIVER_EXPORTED: Use this flag if you want the broadcast receiver to receive broadcasts from other apps, including system broadcasts.
  • RECEIVER_NOT_EXPORTED: Use this flag if the broadcast receiver should only receive broadcasts from your own app and not from other apps.

If neither of these flags is specified when registering a receiver in code, the system will throw a SecurityException with the message: "One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts." Example usage:

java

context.registerReceiver(broadcastReceiver, intentFilter, Context.RECEIVER_EXPORTED);

or

java

context.registerReceiver(broadcastReceiver, intentFilter, Context.RECEIVER_NOT_EXPORTED);

This requirement is for receivers registered programmatically with registerReceiver(). If receivers are registered purely for system broadcasts via the manifest, typically this is handled via android:exported in the manifest. If you do not implement this change, your app will crash on Android 14+ with the above security exception. In summary, this flag indicates whether the receiver is exported to other apps or is private to your own app, and Android requires an explicit declaration since Android 14 for security reasons.