Background
I have a broadcast receiver that declares an intent filter for a system broadcast, as shown below:
<receiver android:name=".StartAppReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
The receiver is correctly receiving broadcasts. However, according to the documentation, this receiver is exported, so other apps can send intents to this receiver.
Question
To prevent other apps from sending intents to the receiver, I can mark it as not exported (android:exported="false"
). I would expect this to also prevent the system from sending intents to it, therefore preventing it from receiving the BOOT_COMPLETED
broadcasts.
However, it still receives the BOOT_COMPLETED
broadcasts despite not being exported, which isn't the behaviour I would expect. I've confirmed this behaviour on:
- Sony Xperia M (Android 4.3 & Android 7.1)
- Genymotion Emulator (Android 6)
- Official Emulator (Android 4.0.1)
I've also tried this with the android.intent.action.MY_PACKAGE_REPLACED
broadcast and got the same result.
This is the behaviour I want, but I would have expected exported="false"
to prevent it from receiving system broadcasts since they're not from my application.
Is it normal that I can receive system broadcasts in broadcast receivers that are not exported? Can I rely on this behaviour?