title: Receive Broadcast only from specific package in android
body: <p>My Sender App will send it's version number to My Receiver App</p>
  <p><em><strong>My Sender App's MainActivity (Initial Activity):</strong></em></p>
  <pre><code>package com.sender.app;
  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     Intent intent = new Intent();
     intent.putExtra(&quot;version&quot;, BuildConfig.VERSION_NAME);
     intent.setAction(&quot;get.sender.app.version&quot;);
     intent.setPackage(&quot;package com.receiver.app;&quot;);
     intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
     sendBroadcast(intent);
  }
  </code></pre>
  <p>=================================</p>
  <p><em><strong>My Receiver App's Manifest:</strong></em></p>
  <pre><code>&lt;receiver
    android:name=&quot;.receivers.BroadcastReceiver_GetSenderAppVersion&quot;
    android:enabled=&quot;true&quot;
    android:exported=&quot;true&quot;&gt;
      &lt;intent-filter&gt;
         &lt;action android:name=&quot;get.sender.app.version&quot; /&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>
  <p><em><strong>My Receiver App's MainActivity (Initial Activity):</strong></em></p>
  <pre><code>@Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     IntentFilter intentFilter = new IntentFilter(&quot;get.sender.app.version&quot;);
     registerReceiver(new BroadcastReceiver_GetSenderAppVersion(), intentFilter);
  }
  </code></pre>
  <p><em><strong>My Receiver App's Broadcast Receiver:</strong></em></p>
  <pre><code>package com.receiver.app;
  public class BroadcastReceiver_GetSenderAppVersion extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
  
  // IT SHOULD COME HERE, ONLY IF IT IS FROM SENDER APP PACKAGE (com.sender.app)
  
          if (intent.hasExtra(&quot;version&quot;) &amp;&amp; intent.getStringExtra(&quot;version&quot;).length() &gt; 0) 
              Toast.makeText(context, intent.getStringExtra(&quot;version&quot;), Toast.LENGTH_LONG).show();
      }
  }
  </code></pre>
  <p>My Receiver App should print the Version number in Toast only if that is coming from Sender App with package id = com.sender.app</p>