Android Question NB6 class... services as the target for button actions?

scsjc

Well-Known Member
Licensed User
Longtime User
hi, can I use services as the target for click action in notification
I check in activity and work fine with get tag intent,

B4X:
    Dim n As NB6
    n.Initialize("default", Application.LabelName, "DEFAULT").SmallIcon(smiley)
    n.Build("bla", "bla", "tag", servicetolaunch).Notify(1)

or call a intent like :

B4X:
Dim nb As NotificationBuilder
   nb.setIntent(open_intent)
 
Last edited:

scsjc

Well-Known Member
Licensed User
Longtime User
Yes. See the "Notification with actions" notification in NB6 example.
Yes, i see this example...working with a "AddButtonAction"...
but is possible dont need show a menu.... ??? click over all box notification ??? and launch a intent or service?
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
Try this:
Modify this line from Build sub:
B4X:
NotificationBuilder.RunMethod("setContentIntent", Array(PendingIntent))
Change it to:
B4X:
NotificationBuilder.RunMethod("setContentIntent", Array(CreateReceiverPendingIntent(YourService, "Test_Action"))

!!! Without words, amazing as always ;) !!!
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
Try this:
Modify this line from Build sub:
B4X:
NotificationBuilder.RunMethod("setContentIntent", Array(PendingIntent))
Change it to:
B4X:
NotificationBuilder.RunMethod("setContentIntent", Array(CreateReceiverPendingIntent(YourService, "Test_Action"))

Your change work perfectly if IsOld=False

In a OldNotification.... can start a service???
i see sample:

B4X:
Sub Activity_Resume
    Dim in As Intent
    in = Activity.GetStartingIntent
    If in.HasExtra("Notification_Tag") Then
        Log(in.GetExtra("Notification_Tag")) 'Will log the tag
    End If
End Sub

only work in Activity? or is possible in Service?
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
Hi,... i
finaly i add intent option, i prefer select intent to open

B4X:
Public Sub Build (ContentTitle As Object, ContentText As Object, Tag As String, Activity As Object, in As Intent) As Notification
   If IsOld Then
       'OldNotification.SetInfo2(ContentTitle, ContentText, Tag, Activity)
       OldNotification.SetInfo2(ContentTitle, ContentText, Tag, in)
       Return OldNotification
   Else
       'Dim in As Intent = CreateIntent(Activity, False)
       in.Flags = Bit.Or(268435456, 131072) 'FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_REORDER_TO_FRONT
       in.PutExtra("Notification_Tag", Tag)
       Dim PendingIntent As Object = PendingIntentStatic.RunMethod("getActivity", Array(ctxt, Rnd(0, 0x7fffffff), in, 0))
       NotificationBuilder.RunMethodJO("setContentTitle", Array(ContentTitle)).RunMethodJO("setContentText", Array(ContentText))

       NotificationBuilder.RunMethod("setContentIntent", Array(PendingIntent))
       'NotificationBuilder.RunMethod("setContentIntent", Array(CreateReceiverPendingIntent(Activity, Tag)))
       
       If IsChannel Then
           Dim manager As JavaObject = ctxt.RunMethod("getSystemService", Array("notification"))
           manager.RunMethod("createNotificationChannel", Array(Channel))
           
       End If
       Return NotificationBuilder.RunMethod("build", Null)
   End If
End Sub
 
Last edited:
Upvote 0
Top