blackfyre blackfyre - 1 month ago 24
Android Question

How to set permissions in broadcast sender and receiver in android

How do we specify in broadcast sending application that which application can receive this broadcast, and in receiving application that which particular application has the permission to send broadcast to its broadcast receiver...

I am new to android..I read the documentation etc on internet but couldn't find the syntax to specify these permissions.

Answer

use an intent filter in receiver tag in manifest

 <receiver
    android:name="Your receiver"
    android:enabled="true"
    android:exported="false" >
    <intent-filter>
        <action android:name="action"/>
        <category android:name="category" />
    </intent-filter>
</receiver>

To send broadcast to app

   Intent intent = new Intent();
   intent.setAction("use same action in receiver");
   intent.addcategory("use same category in receiver");
   context.sendBroadcast(intent); 
Comments