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:

Erel

B4X founder
Staff member
Licensed User
Longtime User


Example code:
B4X:
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.MediaStyle
    n.Build("Actions", "Actions", "tag", Me).Notify(1)
End Sub

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

wes58

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 - https://developer.android.com/reference/android/app/Notification.MediaStyle

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…