title: How do I receive an external app's broadcast metadata?
body: <p>I am trying to add a feature to my app which receives broadcast data/intent-actions from Spotify and does something with that data. However, I am not sure how to proceed. I've been able to piece together the following code with the help of previous questions, however those questions do not go into detail on <strong>how to actually initiate the reception of data</strong>. I have a BroadCast Receiver:</p>
  
  <pre><code>&lt;receiver
      android:name=".Receiver"
      android:enabled="true"
      android:exported="true"&gt;
  
      &lt;intent-filter&gt;
          &lt;action android:name="com.spotify.music.playbackstatechanged"/&gt;
          &lt;action android:name="com.spotify.music.metadatachanged"/&gt;
          &lt;action android:name="com.spotify.music.queuechanged"/&gt;
      &lt;/intent-filter&gt;
  
  &lt;/receiver&gt;
  </code></pre>
  
  <p>I have a BroadCast Receiver class (all set up):</p>
  
  <pre><code>public class Receiver extends BroadcastReceiver {
  
      static final class BroadcastTypes {
          static final String SPOTIFY_PACKAGE = "com.spotify.music";
          static final String PLAYBACK_STATE_CHANGED = SPOTIFY_PACKAGE + ".playbackstatechanged";
          static final String METADATA_CHANGED = SPOTIFY_PACKAGE + ".metadatachanged";
      }
  
      @Override
      public void onReceive(Context context, Intent intent) {
  
          long timeSentInMs = intent.getLongExtra("timeSent", 0L);
          String action = intent.getAction();
  
          if (action.equals(BroadcastTypes.METADATA_CHANGED)) {
  
              String trackId = intent.getStringExtra("id");
              String artistName = intent.getStringExtra("artist");
              String albumName = intent.getStringExtra("album");
              String trackName = intent.getStringExtra("track");
              int trackLengthInSec = intent.getIntExtra("length", 0);
  
              //send data to main class?
  
          } else if (action.equals(BroadcastTypes.PLAYBACK_STATE_CHANGED)) {
  
             boolean playing = intent.getBooleanExtra("playing", false);
              int positionInMs = intent.getIntExtra("playbackPosition", 0);
  
              //send data to main class?
          }
      }
  }
  </code></pre>
  
  <p>I also have the following methods in my main activity:</p>
  
  <pre><code>public void mute(AudioManager audioManager){
  
      audioManager.setStreamMute(am.STREAM_SYSTEM, true);
  
  }
  
  public void unMute(AudioManager audioManager){
  
      audioManager.setStreamMute(am.STREAM_SYSTEM,false);
  
  }
  </code></pre>
  
  <p>which I want to call after receiving and analyzing the BroadCast data from my Receiver class.</p>
  
  <p><strong>In Summary:</strong></p>
  
  <blockquote>
    <p>So now I am not sure how I can actually start the acquisition of data from Spotify in my main activity (whether I have to manually "call" my receiver, or whether it will automatically listen for Broadcasts in the background while my main Activity is running). </p>
  </blockquote>
  
  <p>A detailed explanation would be very much appreciated and will be rewarded. </p>