user1437328
user1437328

Reputation: 15846

How to Set BroadcastReceiver Permissions (Security)

So I have 2 apps - A and B.

In A i have a BroadcastReceiver. In the receiver tag (manifest file) I specify an android:permission string (let's say com.example.app.SEND). Now B cannot send broadcasts to A anymore. Makes sense!

So what do I have to do in order for B to send broadcasts to A ? In B's manifest, I specified uses-permission tag with android:name set to the same string (com.example.app.SEND) as the receiver's android:permission but still the broadcasts won't go from B to A.

What am I doing wrong ? Or is there something else that needs to be done ?

-- Update --

Here's my app A's receiver tag:

    <receiver
        android:name="com.example.app.MyReceiver"
        android:enabled="true"
        android:exported="true"
        android:permission="com.example.BReceiver.SEND" >
        <intent-filter>
            <action android:name="com.example.BReceiver" />
        </intent-filter>
    </receiver>

And here's the uses-permission tag from my B's manifest:

<uses-permission android:name="com.pycitup.BReceiver.SEND" />

Upvotes: 4

Views: 5660

Answers (2)

user1437328
user1437328

Reputation: 15846

So I'd to set a custom permission for the same string like this in B's manifest:

<permission android:name="com.pycitup.BReceiver.SEND" />

Was quite straight-forward and simple. Just required a bit of reading across the web.

Upvotes: 7

archon92
archon92

Reputation: 447

From B create an intent and set the action to your broadcast receivers name.

Intent myintentB=new Intent();
myintentB.setAction("com.example.app.SEND");
sendBroadcast(myintentB);

This should technically hit your receiver.

Upvotes: 0

Related Questions