title: Media Session Compat not showing Lockscreen controls on Pre-Lollipop
body: <p>I'm using <code>MediaSessionCompat</code> from AppCompat Support Library Revision 22. And on Lollipop I'm getting notification &amp; also the background of lockscreen is the album art. And everything works cool.</p>
  
  <p>While on Pre-Lollipop devices, the music controls on lockscreen are not at all shown. It's weird &amp; I tried everything but it doesn't show up, not even the background changes. </p>
  
  <p>I hope someone has solution to this issue. </p>
  
  <p>Note: <code>RemoteControlClient</code> used to work on Lollipop &amp; KitKat</p>
  
  <pre><code>/**
   * Initializes the remote control client
   */
  private void setupMediaSession() {
      /* Activate Audio Manager */
      mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
      mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC,
              AudioManager.AUDIOFOCUS_GAIN);
  
      ComponentName mRemoteControlResponder = new ComponentName(getPackageName(),
              MediaButtonReceiver.class.getName());
      final Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
      mediaButtonIntent.setComponent(mRemoteControlResponder);
      mMediaSessionCompat = new MediaSessionCompat(getApplication(), "JairSession", mRemoteControlResponder, null);
      mMediaSessionCompat.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
      PlaybackStateCompat playbackStateCompat = new PlaybackStateCompat.Builder()
              .setActions(
                      PlaybackStateCompat.ACTION_SEEK_TO |
                      PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS |
                      PlaybackStateCompat.ACTION_SKIP_TO_NEXT |
                      PlaybackStateCompat.ACTION_PLAY |
                      PlaybackStateCompat.ACTION_PAUSE |
                      PlaybackStateCompat.ACTION_STOP
              )
              .setState(
                      isPlaying() ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED,
                      getCurrentPosition(),
                      1.0f)
              .build();
      mMediaSessionCompat.setPlaybackState(playbackStateCompat);
      mMediaSessionCompat.setCallback(mMediaSessionCallback);
      mMediaSessionCompat.setSessionActivity(retrievePlaybackActions(5));
      mMediaSessionCompat.setActive(true);
      updateMediaSessionMetaData();
      mTransportController = mMediaSessionCompat.getController().getTransportControls();
  </code></pre>
  
  <hr>
  
  <p>Here's the <code>updateMediaSessionMetaData()</code> :</p>
  
  <pre><code>/**
   * Updates the lockscreen controls, if enabled.
   */
  private void updateMediaSessionMetaData() {
              MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
              builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, getArtistName());
              builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, getAlbumName());
              builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, getTrackName());
              builder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, getDuration());
              builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, MusicUtils.getArtwork(this, getAlbumID(), true));
              mMediaSessionCompat.setMetadata(builder.build());
  </code></pre>
  
  <p>}</p>
  
  <hr>
  
  <p>The Media Session Callback methods</p>
  
  <pre><code>private final MediaSessionCompat.Callback mMediaSessionCallback = new MediaSessionCompat.Callback() {
  
      @Override
      public boolean onMediaButtonEvent(Intent mediaButtonEvent) {
          final String intentAction = mediaButtonEvent.getAction();
          if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
              if (PrefUtils.isHeadsetPause(getBaseContext())) {
                  Log.d(LOG_TAG, "Headset disconnected");
                  pause();
              }
          } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
              final KeyEvent event = mediaButtonEvent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
              if (event == null) return super.onMediaButtonEvent(mediaButtonEvent);
              final int keycode = event.getKeyCode();
              final int action = event.getAction();
              final long eventTime = event.getEventTime();
              if (event.getRepeatCount() == 0 &amp;&amp; action == KeyEvent.ACTION_DOWN) {
                  switch (keycode) {
                      case KeyEvent.KEYCODE_HEADSETHOOK:
                          if (eventTime - mLastClickTime &lt; DOUBLE_CLICK) {
                              playNext(mSongNumber);
                              mLastClickTime = 0;
                          } else {
                              if (isPlaying())
                                  pause();
                              else resume();
                              mLastClickTime = eventTime;
                          }
                          break;
                      case KeyEvent.KEYCODE_MEDIA_STOP:
                          mTransportController.stop();
                          break;
                      case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
                          if (isMediaPlayerActive()) {
                              if (isPlaying()) mTransportController.pause();
                              else mTransportController.play();
                          }
                          break;
                      case KeyEvent.KEYCODE_MEDIA_NEXT:
                          mTransportController.skipToNext();
                          break;
                      case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
                          mTransportController.skipToPrevious();
                          break;
                      case KeyEvent.KEYCODE_MEDIA_PAUSE:
                          mTransportController.pause();
                          break;
                      case KeyEvent.KEYCODE_MEDIA_PLAY:
                          mTransportController.play();
                          break;
                  }
              }
          }
          return super.onMediaButtonEvent(mediaButtonEvent);
      }
  
      @Override
      public void onPlay() {
          super.onPlay();
          resume();
      }
  
      @Override
      public void onPause() {
          super.onPause();
          pause();
      }
  
      @Override
      public void onSkipToNext() {
          super.onSkipToNext();
          playNext(mSongNumber);
      }
  
      @Override
      public void onSkipToPrevious() {
          super.onSkipToPrevious();
          playPrevious(mSongNumber);
      }
  
      @Override
      public void onSeekTo(long pos) {
          super.onSeekTo(pos);
          seekTo(pos);
      }
  
      @Override
      public void onStop() {
          super.onStop();
          pause();
          commitMusicData();
          updatePlayingUI(STOP_ACTION);
          stopSelf();
      }
  };
  </code></pre>
  
  <hr>
  
  <p>Media Button Receiver Manifest Entry</p>
  
  <pre><code>&lt;!-- Media button receiver --&gt;
      &lt;receiver android:name=".receiver.MediaButtonReceiver" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MEDIA_BUTTON" /&gt;
              &lt;action android:name="android.media.AUDIO_BECOMING_NOISY" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  </code></pre>
  
  <hr>
  
  <p>I'm trying since couple of weeks to solve this issue with no success, and in desperate need of help.</p>
  
  <p>Edit: A tutorial or example of MediaSessionCompat would also be fine</p>