#Region Project Attributes
#ApplicationLabel: B4A Example
#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
#AdditionalJar: com.android.support:support-v4
#AdditionalJar: com.google.android.gms:play-services-location
Sub Process_Globals
Private rp As RuntimePermissions
Private StateMessage As String
End Sub
Sub Globals
Private lblLocation As B4XView
Private lblState As B4XView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
End Sub
Sub Activity_Resume
If StateMessage <> "" Then SetState(StateMessage)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnStart_Click
rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Starter.flp.IsConnected = False Then
SetState("Location provider not available")
End If
If Result Then
Dim rs As ResumableSub = CallSub(Starter, "CheckLocationSettingStatus")
Wait For (rs) Complete (SettingsResult As LocationSettingsResult)
Dim sc As StatusCodes
Select SettingsResult.GetLocationSettingsStatus.GetStatusCode
Case sc.SUCCESS
SettingsAreGood
Case sc.RESOLUTION_REQUIRED
SetState("RESOLUTION_REQUIRED")
SettingsResult.GetLocationSettingsStatus.StartResolutionDialog("srd")
Wait For srd_ResolutionDialogDismissed(LocationSettingsUpdated As Boolean)
If LocationSettingsUpdated Then
SettingsAreGood
Else
SetState("Not enabled")
End If
Case Else
SetState("Not available")
End Select
Else
SetState("No permission")
End If
End Sub
Sub SettingsAreGood
SetState("Location enabled - waiting for updates")
CallSub(Starter, "StartLocationUpdates")
End Sub
Public Sub Location_Changed (loc As Location)
' lblLocation.Text = $"$1.2{loc.Latitude} / $1.2{loc.Longitude}"$
lblLocation.Text = "Acc: " & loc.Accuracy & CRLF & "Valid: " & loc.AccuracyValid
Log(" ")
Log("==== ==== ==== ==== ====")
Log("Acc: " & loc.Accuracy)
Log("Valid: " & loc.AccuracyValid)
Log("Lat: " & loc.Latitude)
Log("Long: " & loc.Longitude)
Log("==== ==== ==== ==== ====")
Log(" ")
End Sub
Sub SetState (msg As String)
StateMessage = msg
lblState.Text = "State: " & msg
Log(lblState.Text)
End Sub