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

1 week ago 8
Nature

The message "One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts" is an Android security requirement introduced starting with Android 13 and mandatory for apps targeting Android 14 or higher. Key points:

  • When registering a broadcast receiver programmatically with context.registerReceiver(), you must specify either the flag RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED.
  • RECEIVER_EXPORTED means the receiver can receive broadcasts from other apps (exported).
  • RECEIVER_NOT_EXPORTED means the receiver cannot receive broadcasts from other apps, only from within the app.
  • This requirement prevents security exceptions at runtime on Android 14+.
  • If a receiver is only for system broadcasts, this flag is not needed.
  • To register, use:
    • context.registerReceiver(broadcastReceiver, intentFilter, RECEIVER_EXPORTED);
    • or context.registerReceiver(broadcastReceiver, intentFilter, RECEIVER_NOT_EXPORTED);
  • This change requires minSdkVersion 26 or higher.
  • Alternatively, for app-local broadcasts, LocalBroadcastManager can be used without these flags.
  • The requirement was introduced following Google I/O 2023 and affects many libraries and apps updating to the newest SDK versions.

In summary, when dynamically registering a broadcast receiver on Android 14 or higher, it is mandatory to specify explicitly if the receiver is exported or not using one of these two flags to comply with security policies and avoid runtime exceptions.