title: Enforcing android permissions within the same app
body: <p>Here is a scenario. My app has </p>
  
  <ul>
  <li>BroadcastSenderActivity  </li>
  <li>SampleBroadcastReceiver</li>
  </ul>
  
  <p>I am using the <code>sendBroadcast(intent, permission)</code> method to send out my broadcast because I would like only my SampleBroadcastReceiver to receive the broadcast message and prevent other receivers in my app from receiving the message. </p>
  
  <p><em><strong>Note:</em></strong> All receivers are registered for the same action but at the time of broadcast based on the system conditions the message will be broadcasted with varying permissions.</p>
  
  <p>From the documentation I learnt that I need the following in the manifest :</p>
  
  <ol>
  <li><p>Need to declare <code>&lt;permission android:name="com.example.MYPERMISSION" 
      android:label="my_permission" 
      android:protectionLevel="normal"&gt;&lt;/permission&gt;</code>
  in the manifest</p></li>
  <li><p>Have this stmt to request for the permission which is at the app level <code>&lt;uses-permission android:name="com.example.MYPERMISSION"/&gt;</code>   </p></li>
  </ol>
  
  <p><em><strong>QUESTION</em></strong> - </p>
  
  <ul>
  <li><p>Instead of app-level permission request how can I request permission only for a particular component in my app? eg. SampleBroadcastReceiver (see code below). Is it possible?* </p></li>
  <li><p>What's the purpose of the <code>&lt;android-permission&gt;</code> tag which is available for all inidividual components? Can it serve my purpose ?</p>
  
  <p>AndroidManifest</p>
  
  <pre><code>    .........
  </code></pre>
  
  <p></p>
  
  <p></p>
  
  <pre><code>&lt;activity
        android:name="com.example.activities.BroadcastSenderActivity"
        android:label="BroadcastSenderActivity"
        android:theme="@android:style/Theme.Light" &gt;
        &lt;intent-filter&gt;
          &lt;action android:name="android.intent.action.MAIN" /&gt;
  
          &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
       &lt;/intent-filter&gt;
  &lt;/activity&gt;
  
  &lt;!-- **************************************  RECEIVER ******************************************* --&gt;
  &lt;receiver android:name="com.example.broadcastTest.SampleBroadcastReceiver"
      android:exported="false"&gt;
      &lt;intent-filter&gt;
          &lt;action android:name="com.example.ACTION_BROADCAST_SEND" /&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  &lt;receiver android:name="com.example.broadcastTest.BroadcastReceiver_1"
      android:exported="false"&gt;
      &lt;intent-filter&gt;
          &lt;action android:name="com.example.ACTION_BROADCAST_SEND" /&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  &lt;receiver android:name="com.example.broadcastTest.BroadcastReceiver_2"
      android:exported="false"&gt;
      &lt;intent-filter&gt;
          &lt;action android:name="com.example.ACTION_BROADCAST_SEND" /&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>
  
  <p></p></li>
  </ul>
  
  <hr>
  
  <pre><code>    public class BroadcastSenderActivity extends Activity {
  
  public BroadcastSenderActivity() {
  
  }
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      Log.d(Logger.TAG, "BroadcastSenderActivity - onCreate");
      setContentView(R.layout.broadcast_tester);
      Button btn = (Button)findViewById(R.id.sendBroadcastBtn);
      btn.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              Intent broadcastIntent = new Intent();
              Log.d(Logger.TAG, "BroadcastSenderActivity - sending the broadcast");
              broadcastIntent.setAction(com.example.ACTION_BROADCAST_SEND);
              BroadcastSenderActivity.this.sendBroadcast(broadcastIntent, com.example.MYPERMISSION);
  </code></pre>