Skip to content

Fix android.broadcast.BroadcastReceiver on Android 14+: pass RECEIVER_EXPORTED / RECEIVER_NOT_EXPORTED - #3400

Open
Fector101 wants to merge 1 commit into
kivy:developfrom
Fector101:fix-broadcast-receiver-export-flag
Open

Fector101 wants to merge 1 commit into
kivy:developfrom
Fector101:fix-broadcast-receiver-export-flag

Conversation

@Fector101

@Fector101 Fector101 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

My BroadcastReceiver is failing on android 15 when on BroadcastReceiver.start() registers with the 4-arg registerReceiver.

On Android 14+, the platform requires RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED for any runtime-registered receiver whose filter is not exclusively protected system broadcasts, so registering for app-defined actions now throws:

java.lang.SecurityException:
 One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified
when a receiver isn't being registered exclusively for system broadcasts

p4a's own Java-side receivers Hardware.java listen only to protected system broadcasts and are exempt, anything registering custom actions from Python crashes in start().

Fixes #3399

Changes

  • broadcast.py: new exported=False keyword on BroadcastReceiver.__init__.

  • On Android 14+ _register_receiver() passes Context.RECEIVER_EXPORTED or Context.RECEIVER_NOT_EXPORTED (default) as the 5th argument.

  • below 14 the original 4-arg call is kept, since the RECEIVER_* constants only exist from API 33.

  • The default is RECEIVER_NOT_EXPORTED (least privilege): same-UID and system broadcasts are still delivered. exported=True is the opt-in for receiving from other apps.

  • doc/source/apis.rst: documents the new parameter.

Verification

Android 15 / API 35 device, targetSdk 36, receiver registered from a foreground service for two app-defined actions, triggered via notification buttons (PendingIntent.getBroadcast + setPackage()):

  • unpatched: br.start() raises the SecurityException above
  • this branch (built via p4a.source_dir): all taps reach the callback, no exception

docs to Android note on changes: https://developer.android.com/about/versions/14/behavior-changes-14#runtime-receivers-exported

start() used implicit flags = 0, which raises a SecurityException on
Android 14+ for app-defined actions. New exported=False keyword; on
SDK 33+ register with the matching flag, below that keep the legacy call.
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 63.278%. remained the same — Fector101:fix-broadcast-receiver-export-flag into kivy:develop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SecurityException in android.broadcast.BroadcastReceiver.start() on Android 14+ (missing RECEIVER_EXPORTED / RECEIVER_NOT_EXPORTED)

2 participants