Reputation: 294
If a BroadcastReceiver is declared in AndroidManifest.xml with intent-filter specified, for example
<receiver
android:name=".receiver.LocationProviderChangeReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
According to http://developer.android.com/guide/topics/manifest/receiver-element.html#exported
The default value depends on whether the broadcast receiver contains intent filters. The absence of any filters means that it can be invoked only by Intent objects that specify its exact class name. This implies that the receiver is intended only for application-internal use (since others would not normally know the class name). So in this case, the default value is "false". On the other hand, the presence of at least one filter implies that the broadcast receiver is intended to receive intents broadcast by the system or other applications, so the default value is "true".
I understand that if the action name is defined as custom one for intent-filter, we should specify exported
as false
as it is true
by default.
But in the above case, the action name tells that it is intended to be called from android OS and hence it doesn't give any warning even if exported flag is not specified (by default it's true)
Specifying the value for exported
in this case as false
does not make any difference and the app still gets the broadcast from OS.
According to the docs:
Whether or not the broadcast receiver can receive messages from sources outside its application — "true" if it can, and "false" if not. If "false", the only messages the broadcast receiver can receive are those sent by components of the same application or applications with the same user ID.
My assumption is that broadcast sent by android system is a source that is outside the application. What is exactly happening here?
exported
in this case not overridden by the value explicitly specified?Upvotes: 0
Views: 2021
Reputation: 3812
The android:exported
attribute is used to indicate/limit a broadcast receiver's external exposure. The default value of android:exported
is not true
, nor is it false
here the documentation is very clear. According to the documentation, the default value of android:exported
depends on whether the broadcast receiver contains intent filters. Furthermore, if there are no filters, then the value false
is the default. So although it might seem that there is no point, the idea is that during design time, you can decide which behavior you desire (by specifying filters - or if not applicable, explicitly setting android:exported
to false
). Of course setting android:exported
to false
whilst specifying filters is not useful because specifying at least one filter implies that the broadcast receiver is intended to receive intents broadcast by the system or other applications.
Upvotes: 2