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

AddAction (icon As String, title As String, tag As String, Activity As Object)
Adds an Action to the notification.

Actions are buttons displayed on the notification that can allow users to do something without starting the app. e.g Call back a missed call, pause a sound track, etc

The icon file should manually copied to the Objects\res\drawable\ folder and set to read-only.
The file name is case sensitive and should not contain the file extension.
If tag is set to "" then it will default to the passed title.

tags are named 'Notification_Action_Tag'

Use AddAction2 to pass a Service module instead of an Activity.

MAXIMUM of 3 Actions can be added to each notification.

API 16+

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
Top