Android Question NB6 - Notifications Builder class (2018) - Actions

stari

Active Member
Licensed User
Longtime User
I try sample NB6, wery nice.
Question: how can i start main activity from service (MyService ) ?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The correct thing is to start the activity from the notification.

It is done with AddButtonAction2. If it is missing from NB6 then this is the code:
B4X:
'Similar to AddButtonAction. Starts an activity instead of a service.
Public Sub AddButtonAction2 (Bmp As Bitmap, Title As Object,  Activity As Object, Action As String) As NB6
    If IsBuilder = False Then Return Me
    Dim in As Intent = CreateIntent(Activity, False)
    in.Action = Action
    in.Flags = Bit.Or(268435456, 131072) 'FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_REORDER_TO_FRONT
    Dim PendingIntent As Object = PendingIntentStatic.RunMethod("getActivity", Array(ctxt, Rnd(0, 0x7fffffff), in, 0))
    NotificationBuilder.RunMethod("setContentIntent", Array(PendingIntent))
    Dim Ac As Object = CreateAction(Bmp, Title, PendingIntent)
    NotificationBuilder.RunMethod("addAction", Array(Ac))
    Return Me
End Sub
 
Upvote 0
Top