Android Question Notification - audio play / pause button

Jack Cole

Well-Known Member
Licensed User
Longtime User
Is there a way to have a play/pause button like Audible has in the notification? In the screenshot below, I show the closest thing I could find with the nb6 class. But it requires you to pull down the notification to show the actions. Contrast with the Audible notification above that.

Last edited:


B4X founder
Staff member
Licensed User
Longtime User

Example code:
Sub MediaStyle_Notification
    Dim n As NB6
    n.Initialize("default", Application.LabelName, "DEFAULT").SmallIcon(smiley)
    n.AddButtonAction(smiley, "Action 1", MyService, "action 1") 'use different bitmaps...
    n.AddButtonAction(smiley, "Action 2", MyService, "action 2")
    n.AddButtonAction(smiley, "Action 3", MyService, "action 3")
    n.Build("Actions", "Actions", "tag", Me).Notify(1)
End Sub

Add to NB6:
'Creates a media style notification
Public Sub MediaStyle As NB6
    If IsBuilder Then
        SetStyle("$MediaStyle", CreateMap("setShowActionsInCompactView": Array As Int(0, 1, 2)))
    End If
    Return Me
End Sub
Upvote 0


Active Member
Licensed User
Longtime User
Just a note, that example shown by Erel in post #2 is not a full android Notification.MediaStyle as described there -

Notifications created with MediaStyle will have their category set to Notification#CATEGORY_TRANSPORT unless you set a different category using Notification.Builder#setCategory(String).

Finally, if you attach a MediaSession.Token using setMediaSession(MediaSession.Token), the System UI can identify this as a notification representing an active media session and respond accordingly (by showing album artwork in the lockscreen, for example).

To use this style with your Notification, feed it to Notification.Builder#setStyle( like so:

Notification noti = new Notification.Builder()
.setContentTitle("Track title")
.setContentText("Artist - Album")
.setStyle(new Notification.MediaStyle()
Upvote 0