Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To control who is able to receive the broadcast message, you can use the method <a href="http://developer.android.com/reference/android/content/Context.html#sendBroadcast%28android.content.Intent,%20java.lang.String%29" rel="noreferrer">sendBroadcast</a>:</p> <pre><code>public abstract void sendBroadcast (Intent intent, String receiverPermission) </code></pre> <p>where you precise the name of the required permission. If the receiver does not declare this permission, it will not be able to get the message. For example, the broadcast sender can do:</p> <pre><code>Intent broadcast = new Intent(this, MyBroadcastReceiver.class); sendBroadcast(broadcast, "andro.jf.mypermission"); </code></pre> <p>In the manifest of the broadcast sender, a new permission should be declared:</p> <pre><code>&lt;!-- Declaring the special permission --&gt; &lt;permission android:name="andro.jf.mypermission" android:label="my_permission" android:protectionLevel="dangerous"&gt;&lt;/permission&gt; </code></pre> <p>Then, in the application that is supposed to receive this broadcast, you have to declare this permission and say that you use it. In the manifest you can add:</p> <pre><code>&lt;!-- I use the permission ! --&gt; &lt;uses-permission android:name="andro.jf.mypermission"/&gt; </code></pre> <p>and of course, you have to declare your broadcast receiver:</p> <pre><code>&lt;receiver android:name="MyBroadcastReceiver" android:exported="true" /&gt; </code></pre> <p>You can have a look at <a href="https://stackoverflow.com/a/8817231/1156363">this post</a> for a complete example of a custom permission and also the <a href="http://developer.android.com/guide/topics/security/permissions.html#declaring" rel="noreferrer">android developer page</a> about this. Be carefull with the order of installation of your apps because the one that defines the permission <a href="https://stackoverflow.com/a/4426512/1156363">should be installed first</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload