Class NotificationButton

java.lang.Object
com.jwplayer.pub.api.background.NotificationButton

public final class NotificationButton extends Object
A button on the background-audio notification and, where the system supports it, on the lock screen, the Android 13+ system media controls, Bluetooth and Android Auto.

Return these from ServiceMediaApi.getNotificationButtons(android.content.Context). A tap on a custom button is delivered to ServiceMediaApi.onNotificationButtonClick(String) on the main thread, with the button's id.


 new NotificationButton.Builder("like", R.drawable.ic_like, "Like")
         .compactViewIndex(2)         // third button in the collapsed notification
         .enabled(!alreadyLiked)      // shown but does nothing when false
         .placement(NotificationButton.PLACEMENT_OVERFLOW)
         .build();
 

Limits:

  • At most 10 custom buttons are used; more are dropped. In practice 3 to 5 is the most the system shows: extra buttons may not be shown at all, depending on the Android version and the device.
  • Android 12 and below show at most 5 actions in the expanded notification, built-in controls included, and an automatically added play/pause, which goes first, counts too; later ones are dropped, so order matters.
  • The icon must be a drawable resource.
  • On Android 13 and later the system media controls lay out the buttons themselves: they ignore NotificationButton.Builder.compactViewIndex(int) and do not show disabled buttons.
  • Field Details

    • COMPACT_VIEW_NONE

      public static final int COMPACT_VIEW_NONE
      Not shown in the collapsed (compact) notification.
      See Also:
    • PLACEMENT_OVERFLOW

      public static final int PLACEMENT_OVERFLOW
      Shown with the other extra buttons. On Android 13+ system controls this is the slot to the side of the transport controls.
      See Also:
    • PLACEMENT_BACK

      public static final int PLACEMENT_BACK
      Asks the system media controls (Android 13+, Android Auto, other media controllers) to put this button in the "previous" slot. Used only when previous is not available; otherwise the button goes to the overflow with the other extra buttons. The notification itself shows buttons in list order.
      See Also:
    • PLACEMENT_FORWARD

      public static final int PLACEMENT_FORWARD
      Asks the system media controls (Android 13+, Android Auto, other media controllers) to put this button in the "next" slot. Used only when next is not available; otherwise the button goes to the overflow with the other extra buttons. The notification itself shows buttons in list order.
      See Also:
  • Method Details