If you want to protect your broadcasts not to be received by other applications directly, one permission is required to define in the AndroidManifest.xml as follows,
<permission android:name="test.permission.intent"/>
Intent intentA= new Intent("test.intent.a");
sendBroadcast(intentA,"test.permission.intent"/);
If you only define this permission and not use this one, your app's receivers also can not receive the intents.
So if want to monitor these intents with permissions, we should add one uses-permission in the AndroidManifestxml.
<uses-permission android:name="test.permission.intent"/>
If you do not want to receive any intent outside of your application, "export = false" in the AndroidManifest.xml is helpful.
<receiver android:name="test.broadcastreceiver"
android:exported="false">
......
< /receiver>
LocalBroadcastManager
Helper to register for and send broadcasts of Intents to local objects within your process. This is has a number of advantages over sending global broadcasts with sendBroadcast(Intent)
:
- You know that the data you are broadcasting won't leave your app, so don't need to worry about leaking private data.
- It is not possible for other applications to send these broadcasts to your app, so you don't need to worry about having security holes they can exploit.
- It is more efficient than sending a global broadcast through the system.