Android Question Notification AddAction

Alexander Stolte

Expert
Licensed User
Longtime User
Hello Guys,

I want to realize that the user gets a message on the display and he with 2 buttons in the message are decide what he wants to make, I just fail to do that when I touch the buttons that always the activity opens instead of the function

My Code:
B4X:
Sub Button1_Click
    nb.Initialize
    WearableExtender.Initialize
    WearableExtender.Gravity = WearableExtender.TOP
    nb.SmallIcon = "icon"
    nb.Ticker = "New Demo"
    nb.Tag = "someTag"
    nb.setActivity(Me)
    nb.DefaultLight = False
    nb.DefaultVibrate = False
    nb.DefaultSound = False
    nb.ContentTitle = "Title"
    nb.ContentInfo = "Info"
    nb.ShowTime = False
    'nb.Extend(WearableExtender)
   
    nb.AddAction("actionicon1", "Aktion 1","Tag1",MyGreatFunction1)
    nb.AddAction("actionicon2", "Aktion 2", "Tag2", MyGreatFunction2)
   
    WearableExtender.AddAction("actionicon1", "Aktion 1","Tag1",MyGreatFunction1)
    WearableExtender.AddAction("actionicon2", "Aktion 2", "Tag2", MyGreatFunction2)
    nb.Notify(0)
End Sub

If I click the button to get the message then the two functions are executed, but this is not what I want, but the should be executed only when I click Action 1 or Action 2

I have not found anything that explains in detail, I seem to be the only one who does not know how to do that.
 

DonManfred

Expert
Licensed User
Longtime User
AddAction expect an activity as last parameter. Not a method


Did you tried to use different Activities for the actions?

Alternatively you can use two services and use AddAction2
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
My configuration:
B4X:
nb.Initialize
    WearableExtender.Initialize
    WearableExtender.Gravity = WearableExtender.TOP
    nb.SmallIcon = "icon"
    nb.Ticker = "New Demo"
    nb.Tag = "someTag"
    nb.setActivity(Me)
    nb.DefaultLight = False
    nb.DefaultVibrate = False
    nb.DefaultSound = False
    nb.ContentTitle = "Title"
    nb.ContentInfo = "Info"
    nb.ShowTime = False
    'nb.Extend(WearableExtender)
   
    nb.AddAction("icon001", "title001","Tag1",Service1)
    nb.AddAction("icon002", "title002", "Tag2", Service2)
   
    WearableExtender.AddAction("icon001", "title001","Tag1",Service1)
    WearableExtender.AddAction("icon002", "title002","Tag2",Service2)
    nb.Notify(0)

I have no experience with "Intent"

B4X:
 Dim In As Intent
   Dim intentExtra As String

   In = Activity.GetStartingIntent
   Log(In.ExtrasToString)

   If In.HasExtra("Tag1") Then 'from a standard notification action
     intentExtra = In.GetExtra("Tag1")
     ToastMessageShow(intentExtra, False)
   End If
   
   If In.HasExtra("Tag1") Then 'from a Wear notification action
     If In.GetExtra("Tag1") = "RemAction" Then
       Dim rem As NotificationRemoteInput
       ToastMessageShow(rem.GetRemoteInput(In, "Action_Reply"), False)
     Else
       intentExtra = In.GetExtra("Tag1")
       ToastMessageShow(intentExtra, False)
     End If
   End If

Is it correct that way ?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…