title: Media Style Notification action buttons not working with PendingIntent.getBroadcast()
body: <p>I am creating a music player with notification style by using <code>NotificationCompat.MediaStyle()</code>.</p>
  
  <p>I implemented my code to send a broadcast when the action buttons are clicked in my notification. But my code doesn't seems to work. </p>
  
  <p>Here's my code as follows:</p>
  
  <pre><code>NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
              .setShowWhen(false)
              // Set the Notification style
              .setStyle(new NotificationCompat.MediaStyle()
                        // Attach our MediaSession token
                        .setMediaSession(mediaSession.getSessionToken())
                        // Show our playback controls in the compact notification view.
                        .setShowActionsInCompactView(0, 1, 2))
              // Set the Notification color
              .setColor(getResources().getColor(R.color.colorPrimary))
              // Set the large and small icons
              .setLargeIcon(largeIcon)
              .setSmallIcon(android.R.drawable.stat_sys_headset)
              // Set Notification content information
              .setContentText("Artist Name")
              .setContentTitle("Album name")
              .setContentInfo("Title name")
              // Add playback actions
              .addAction(android.R.drawable.ic_media_previous, "previous", playbackAction(3))
              .addAction(notificationAction, "pause", play_pauseAction)
              .addAction(android.R.drawable.ic_media_next, "next", playbackAction(2));
  
  ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, notificationBuilder.build());
  </code></pre>
  
  <p>Method <code>playBackAction()</code> is as follows: </p>
  
  <pre><code>private PendingIntent playbackAction(int actionNumber){
  
          Intent playbackAction;
  
          switch(actionNumber){
          case 0:
              // Play
              playbackAction = new Intent(BROADCAST_PLAYBACK);
              playbackAction.setAction(ACTION_PLAY);
  
              return PendingIntent.getBroadcast(this, actionNumber, playbackAction, 0);
          case 1:
              // Pause
              playbackAction = new Intent(BROADCAST_PLAYBACK);
              playbackAction.setAction(ACTION_PAUSE);
  
              return PendingIntent.getBroadcast(this, actionNumber, playbackAction, 0);
          case 2:
              // Next track
              playbackAction = new Intent(BROADCAST_PLAYBACK);
              playbackAction.setAction(ACTION_NEXT);
  
              return PendingIntent.getService(this, actionNumber, playbackAction, 0);
          case 3:
              // Previous track
              playbackAction = new Intent(BROADCAST_PLAYBACK);
              playbackAction.setAction(ACTION_PREVIOUS);
  
              return PendingIntent.getBroadcast(this, actionNumber, playbackAction, 0);
          default:
              break;
          }
          return null;
      }
  </code></pre>
  
  <p>My BroadcastReceiver is as follows:</p>
  
  <pre><code>BroadcastReceiver broadCastPlayback=new BroadcastReceiver(){
  
          @Override
          public void onReceive(Context context, Intent intent)
          {
              // TODO: Implement this method
  
              showToast("onReceive");
          }
      };
  </code></pre>
  
  <p>I registered the broadcast receiver in <code>onCreate</code> of the android <code>service</code></p>
  
  <pre><code>IntentFilter filter=new IntentFilter(BROADCAST_PLAYBACK);
  registerReceiver(broadCastPlayback,filter);
  </code></pre>
  
  <p>The <code>showToast()</code> method inside <code>onReceive</code> is not called. I wonder whether the <code>broadcast</code> is not sent or it is not received. </p>