<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's needed to be notified. If it were true any app could call my receiver with those actions? So If I make it false the system can send the actions to my receiver?
The exported attribute is used to define if an activity, service, or receiver in your app is accessible and can be launched from an external application. As a practical example, if you try to share a file you'll see a set of applications available.
android:exported 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.
An exported activity is the one that can be accessed by external components or apps. We can say that exported activities are like Public functions in Java, any other parent class or even package can call them.
Open the Phone app and tap Keypad, then type *#0*#. A diagnostic screen pops up with buttons for a variety of tests. Tap Red, Green, or Blue to test those pixel colors. Tap Receiver to check the audio, Vibration to try the vibrating feature, or Sensor to test the accelerometer and other sensors.
I don't understand if it's needed to be notified. If it were true any app could call my receiver with those actions? So If I make it false the system can send the actions to my receiver?
Actually, others apps cannot "call your receiver". Other apps can just send broadcast Intent
s. The System will then call all registered receivers.
In general you shouldn't worry about this. Most of these broadcast Intent
s are protected so that only system apps can broadcast them anyway. An attempt by another app to broadcast BOOT_COMPLETED
, for example, would just be ignored. What would happen if your BroadcastReceiver
gets triggered by a rogue app because it broadcast CONNECTIVITY_CHANGE
? Probably nothing, because your app should check the real connectivity state in onReceive()
anyway, and if there isn't any change you can just ignore it.
Also, you don't 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>
which automatically sets android:exported
to true
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With