androidandroid-broadcastandroid-broadcastreceiverandroid-security

prevent other apps from sending broadcasts to my broadcastReceiver


I have a broadcastReceiver registered in manifest that receives broadcasts sent from one of my services with a custom action. I have it already working but for security reasons i want to prevent other apps from sending fake broadcast to my receiver. How can i do that?

Manifest

<receiver android:name=".MyReceiver">
    <intent-filter>
        <action android:name="MyAction"/>
    </intent-filter>
</receiver>

Solution

  • Every reciever with exported tag set to false will only receive broadcasts sent from its own application process.

    so it will be:

    <receiver android:name=".MyReceiver"
              android:exported="false">
        <intent-filter>
            <action android:name="MyAction"/>
        </intent-filter>
    </receiver>