Hi all, I have an app that schedules a notification for the user, the notification has two action buttons, "Check In" and "Close", I have a receiver that captures these actions in the starting intent, based on which of these two buttons are pressed when the user opens the notification, I need to open a B4XPage named "CheckIn", I'm not very familiar how to handle this on a B4XPages project, I know with a regular Activities project, I would normally just call StartActivity(CheckIn).
How can I accomplish the same with a B4XPages project, I have tried the following...
But this doesn't open the page, in addition I have added the "android.permission.SYSTEM_ALERT_WINDOW" permission and handle the permission request like this
But this still doesn't open the CheckIn B4XPage, If I click on the notification itself, then the B4XMainPage is opened, but that's not the action I require.
How can I get the CheckIn Page to open directly when the user pressed on the "CheckIn" Action button on the notification?
Here's the code where the notification gets created:
And here's the code from MyReceiver that captures the actions from the notification:
What am I missing?
How can I accomplish the same with a B4XPages project, I have tried the following...
B4X:
B4XPages.ShowPageAndRemovePreviousPages("CheckIn")
B4XPages.GetPage("CheckIn").As(CheckIn).AnimateFromRight
Request Permission:
Public Sub GetPermission As ResumableSub
If phone.SdkVersion >= 23 Then
Dim settings As JavaObject
settings.InitializeStatic("android.provider.Settings")
Dim ctxt As JavaObject
ctxt.InitializeContext
If settings.RunMethod("canDrawOverlays", Array(ctxt)) = True Then
Return True
End If
Dim i As Intent
i.Initialize("android.settings.action.MANAGE_OVERLAY_PERMISSION", "package:" & Application.PackageName)
StartActivityForResult(i)
Wait For ion_Event (MethodName As String, Args() As Object)
Return settings.RunMethod("canDrawOverlays", Array(ctxt))
Else
Return True
End If
End Sub
Private Sub StartActivityForResult(i As Intent)
Dim jo As JavaObject = GetBA
ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub
Private Sub GetBA As Object
Dim jo As JavaObject = Me
Return jo.RunMethod("getBA", Null)
End Sub
But this still doesn't open the CheckIn B4XPage, If I click on the notification itself, then the B4XMainPage is opened, but that's not the action I require.
How can I get the CheckIn Page to open directly when the user pressed on the "CheckIn" Action button on the notification?
Here's the code where the notification gets created:
Notification Creation:
Sub Process_Globals
Private icon As Bitmap
End Sub
'Called when an intent is received.
'Do not assume that anything else, including the starter service, has run before this method.
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
Log("Starting intent: " & StartingIntent)
icon.Initialize(File.DirAssets, "ellustr_24x24.png")
Dim n As NB6
n.Initialize("default", Application.LabelName, "DEFAULT").SmallIcon(icon)
n.AddButtonAction(icon, "Check In", MyReceiver, "Check In")
Dim cs As CSBuilder
n.AddButtonAction(Null, cs.Initialize.Color(Colors.Red).Bold.Append("Close").PopAll, MyReceiver, "Close")
n.DeleteAction(MyReceiver, "Delete")
n.Build("14 day check up", "This is your 2 week check in, would you like to review your posture?", "tag", Main).Notify(1)
End Sub
And here's the code from MyReceiver that captures the actions from the notification:
MyReceiver:
'Called when an intent is received.
'Do not assume that anything else, including the starter service, has run before this method.
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
If StartingIntent.IsInitialized Then
Dim cs As CSBuilder
cs.Initialize.Bold.Size(20).Append($"Action: ${StartingIntent.Action}"$).PopAll
Log(cs)
If StartingIntent.Action = "Check In" Then
B4XPages.ShowPageAndRemovePreviousPages("CheckIn")
B4XPages.GetPage("CheckIn").As(CheckIn).AnimateFromRight
End If
ToastMessageShow(cs, True)
End If
End Sub
What am I missing?