#Region Project Attributes
#ApplicationLabel: GetGPS
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
#BridgeLogger: true
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim Permissions As List
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("main")
Permissions.Initialize
Permissions.Add(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
Permissions.Add(Starter.rp.PERMISSION_SEND_SMS)
Permissions.Add(Starter.rp.PERMISSION_RECEIVE_SMS)
Permissions.Add(Starter.BACKGROUND_LOCATION_PERMISSION)
End Sub
Sub Activity_Resume
For Each Permission As String In Permissions
If Starter.rp.Check(Permission) = False Then
Sleep(200)
Starter.rp.CheckAndRequest(Permission)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
Log(Permission)
If Result = False Then
ToastMessageShow("No permission " & Permission, True)
Starter.rp.CheckAndRequest(Permission)
Sleep(200)
Return
End If
End If
Next
' TBC /
Wait For (CheckAndRequestNotificationPermission) Complete (HasPermission As Boolean)
If HasPermission = False Then
Log("no permission")
ToastMessageShow("no permission", True)
Return
End If
' TBC /
Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
If Starter.phone.SdkVersion >= 34 Then
'This is only required for the case where the Tracker service is started after boot.
'In other cases it is considered to be running in the foreground.
If Starter.rp.Check(Starter.BACKGROUND_LOCATION_PERMISSION) = False Then
MsgboxAsync("Please allow app to always allow location services", "")
Wait For Msgbox_Result (unused As Int)
Dim in As Intent
in.Initialize("android.settings.LOCATION_SOURCE_SETTINGS", "")
StartActivity(in)
'catch the Activity_Resume event to prevent an endless loop if the user denies the permission.
Wait For Activity_Resume
End If
End If
StartService(Tracker)
Else
ToastMessageShow("No permission...", True)
End If
End Sub
' TBC /
Private Sub CheckAndRequestNotificationPermission As ResumableSub
Dim p As Phone
If p.SdkVersion < 33 Then Return True
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim targetSdkVersion As Int = ctxt.RunMethodJO("getApplicationInfo", Null).GetField("targetSdkVersion")
If targetSdkVersion < 33 Then Return True
Dim NotificationsManager As JavaObject = ctxt.RunMethod("getSystemService", Array("notification"))
Dim NotificationsEnabled As Boolean = NotificationsManager.RunMethod("areNotificationsEnabled", Null)
If NotificationsEnabled Then Return True
Dim rp As RuntimePermissions
rp.CheckAndRequest(rp.PERMISSION_POST_NOTIFICATIONS)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean) 'change to B4XPage_PermissionResult if B4XPages project
Log(Permission & ": " & Result)
Return Result
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub