Android: what's the point of exported attribute of receiver?

<receiver android:name="MyReceiver" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> 

I donโ€™t understand if it needs to be notified. If true, can any application call my recipient with these actions? So, if I make it false, can the system send actions to my recipient?

+10
source share
3 answers

I donโ€™t understand if it needs to be notified. If this is true, can the application call my receiver with these actions? Therefore, if I make it false the system can send actions to my receiver?

Actually, other applications cannot "call your receiver". Other applications may simply send Intent s broadcast messages. Then the system will call all registered recipients.

In general, you should not worry about this. Most of these Intent broadcasts are protected, so in any case they can be broadcast only system applications. For example, an attempt by another application to broadcast BOOT_COMPLETED simply ignored. What happens if your BroadcastReceiver is launched by a rogue application because it passes CONNECTIVITY_CHANGE ? Probably nothing, because your application should check the real connection status in onReceive() in any case, and if there are no changes, you can simply ignore it.

In addition, you do not need to specify android:enabled="true" , because this is the default state. You also don't need to specify android:exported="true" because you have an <intent-filter> attached to your <receiver> that automatically sets android:exported to true .

+16
source

If you set android:exported ="false" , it means that the recipient is for internal use by the application only.

Note. This attribute is not the only way to limit the external exposure of the broadcast receiver. You can also use permission to restrict external objects that can send messages to it.

+3
source

What if we set android: exported = "false" with an intent filter to get a system broadcast? Will the recipient receive system broadcasts?

0
source

All Articles