Package com.jwplayer.pub.api.background
Class NotificationButton
java.lang.Object
com.jwplayer.pub.api.background.NotificationButton
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic @interface -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intNot shown in the collapsed (compact) notification.static final intAsks the system media controls (Android 13+, Android Auto, other media controllers) to put this button in the "previous" slot.static final intAsks the system media controls (Android 13+, Android Auto, other media controllers) to put this button in the "next" slot.static final intShown with the other extra buttons. -
Method Summary
Modifier and TypeMethodDescriptionbooleanint0 to 2, orCOMPACT_VIEW_NONE.intgetId()The id passed toServiceMediaApi.onNotificationButtonClick(String).intgetTitle()inthashCode()booleantoString()
-
Field Details
-
COMPACT_VIEW_NONE
public static final int COMPACT_VIEW_NONENot shown in the collapsed (compact) notification.- See Also:
-
PLACEMENT_OVERFLOW
public static final int PLACEMENT_OVERFLOWShown 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_BACKAsks 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_FORWARDAsks 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
-
getId
The id passed toServiceMediaApi.onNotificationButtonClick(String). -
getIconResId
@DrawableRes public int getIconResId() -
getTitle
-
isEnabled
public boolean isEnabled() -
getCompactViewIndex
public int getCompactViewIndex()0 to 2, orCOMPACT_VIEW_NONE. -
getPlacement
public int getPlacement() -
equals
-
hashCode
public int hashCode() -
toString
-