title: onSkipToNext() and onSkipToPrevious() of MediaSessionCompat.Callback does not get triggered
body: <p>I'm trying to implement a notification player in Android. I followed <a href="https://code.tutsplus.com/tutorials/background-audio-in-android-with-mediasessioncompat--cms-27030" rel="noreferrer">this</a> guide to achieve this. However as my requirement I need to implement "skip to next" and "skip to previous" in the background notification player.</p>
  
  <p>So far onPlay() and onPause() of MediaSessionCompact.Callback get triggered. However while debugging I noticed onSkipToNext() and onSkipToPrevious() callback methods does not get triggered when next and previous buttons are pressed in notification player. </p>
  
  <p>Appreciate your input. I have added relevant code below.  </p>
  
  <p><strong>BackgroundAudioService</strong></p>
  
  <pre><code>private void showPlayingNotification() {
      NotificationCompat.Builder builder = MediaStyleHelper.from(BackgroundAudioService.this, mMediaSessionCompat);
      if (builder == null) {
          return;
      }
  
      builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_previous, "Previous", MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS)));
      builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_pause, "Pause", MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_PLAY_PAUSE)));
      builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_next, "Next", MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_SKIP_TO_NEXT)));
  
      builder.setStyle(new NotificationCompat.MediaStyle().setShowActionsInCompactView(0).setMediaSession(mMediaSessionCompat.getSessionToken()));
      builder.setSmallIcon(R.mipmap.ic_launcher);
      NotificationManagerCompat.from(BackgroundAudioService.this).notify(1, builder.build());
  }
  
  private void showPausedNotification() {
      NotificationCompat.Builder builder = MediaStyleHelper.from(this, mMediaSessionCompat);
      if (builder == null) {
          return;
      }
  
      builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_previous, "Previous", MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS)));
      builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_play, "Play", MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_PLAY_PAUSE)));
      builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_next, "Next", MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_SKIP_TO_NEXT)));
  
  
      builder.setStyle(new NotificationCompat.MediaStyle().setShowActionsInCompactView(0).setMediaSession(mMediaSessionCompat.getSessionToken()));
      builder.setSmallIcon(R.mipmap.ic_launcher);
      NotificationManagerCompat.from(this).notify(1, builder.build());
  }
  
  private MediaSessionCompat.Callback mMediaSessionCallback = new MediaSessionCompat.Callback() {
  
      @Override
      public void onPlay() {
          super.onPlay();
          if (!successfullyRetrievedAudioFocus()) {
              return;
          }
  
          mMediaSessionCompat.setActive(true);
          setMediaPlaybackState(PlaybackStateCompat.STATE_PLAYING);
          Log.d("MyLog", "STATE_PLAYING");
          showPlayingNotification();
          mMediaPlayer.start();
      }
  
      @Override
      public void onPause() {
          super.onPause();
  
          if (mMediaPlayer.isPlaying()) {
              mMediaPlayer.pause();
              setMediaPlaybackState(PlaybackStateCompat.STATE_PAUSED);
              Log.d("MyLog", "STATE_PAUSED");
              showPausedNotification();
          }
      }
  
      @Override
      public void onSkipToNext() {
          super.onSkipToNext();
          setMediaPlaybackState(PlaybackStateCompat.STATE_SKIPPING_TO_NEXT);
          Log.d("MyLog", "STATE_SKIPPING_TO_NEXT");
      }
  
      @Override
      public void onSkipToPrevious() {
          super.onSkipToPrevious();
          setMediaPlaybackState(PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS);
          Log.d("MyLog", "STATE_SKIPPING_TO_PREVIOUS");
      }
  }
  </code></pre>
  
  <p><strong>MediaStyleHelper</strong></p>
  
  <pre><code>public static NotificationCompat.Builder from(
          Context context, MediaSessionCompat mediaSession) {
      MediaControllerCompat controller = mediaSession.getController();
      MediaMetadataCompat mediaMetadata = controller.getMetadata();
      MediaDescriptionCompat description = mediaMetadata.getDescription();
  
      NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
      builder
              .setContentTitle(description.getTitle())
              .setContentText(description.getSubtitle())
              .setSubText(description.getDescription())
              .setLargeIcon(description.getIconBitmap())
              .setContentIntent(controller.getSessionActivity())
              .setDeleteIntent(
                      MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_STOP))
              .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
      return builder;
  }
  </code></pre>
  
  <p><strong>MainActivity</strong>'s onCreate</p>
  
  <pre><code>    mMediaBrowserCompat = new MediaBrowserCompat(this, new ComponentName(this, BackgroundAudioService.class),
              mMediaBrowserCompatConnectionCallback, getIntent().getExtras());
  </code></pre>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>private MediaBrowserCompat.ConnectionCallback mMediaBrowserCompatConnectionCallback = new MediaBrowserCompat.ConnectionCallback() {
  
      @Override
      public void onConnected() {
          super.onConnected();
          try {
              mMediaControllerCompat = new MediaControllerCompat(MainActivity.this, mMediaBrowserCompat.getSessionToken());
              mMediaControllerCompat.registerCallback(mMediaControllerCompatCallback);
              setSupportMediaController(mMediaControllerCompat);
              getSupportMediaController().getTransportControls().playFromMediaId(String.valueOf(R.raw.warner_tautz_off_broadway), null);
  
          } catch( RemoteException e ) {
  
          }
      }
  };
  
  private MediaControllerCompat.Callback mMediaControllerCompatCallback = new MediaControllerCompat.Callback() {
  
      @Override
      public void onPlaybackStateChanged(PlaybackStateCompat state) {
          super.onPlaybackStateChanged(state);
          if( state == null ) {
              return;
          }
  
          switch( state.getState() ) {
              case PlaybackStateCompat.STATE_PLAYING: {
                  mCurrentState = STATE_PLAYING;
                  break;
              }
              case PlaybackStateCompat.STATE_PAUSED: {
                  mCurrentState = STATE_PAUSED;
                  break;
              }
              case PlaybackStateCompat.STATE_SKIPPING_TO_NEXT: {
                  mCurrentState = STATE_SKIPPING_TO_NEXT;
                  break;
              }
              case PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS: {
                  mCurrentState = STATE_SKIPPING_TO_PREVIOUS;
              }
          }
      }
  };
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>Seems like onMediaButtonEvent() gets triggered for next and previous in notification player with action name "android.intent.action.MEDIA_BUTTON" for both buttons.  </p>
  
  <pre><code>    @Override
      public boolean onMediaButtonEvent(Intent mediaButtonEvent) {
          Log.d("MyLog", "executing onMediaButtonEvent: " + mediaButtonEvent.getAction());
          return super.onMediaButtonEvent(mediaButtonEvent);
      }
  </code></pre>