#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
Public flp As FusedLocationProvider
Private nid As Int = 1
Private lock As PhoneWakeState
End Sub
Sub Service_Create
flp.Initialize("flp")
flp.Connect
lock.PartialLock
End Sub
Sub flp_ConnectionSuccess
Log("Connected to location provider")
End Sub
Sub flp_ConnectionFailed(ConnectionResult1 As Int)
Log("Failed to connect to location provider")
End Sub
Sub Service_Start (StartingIntent As Intent)
' Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
Service.StartForeground(nid, CreateNotification("waiting.."))
End Sub
Sub CheckLocationSettingStatus As ResumableSub
Dim f As LocationSettingsRequestBuilder
f.Initialize
f.AddLocationRequest(CreateLocationRequest)
flp.CheckLocationSettings(f.Build)
Wait For flp_LocationSettingsChecked(LocationSettingsResult1 As LocationSettingsResult)
Return LocationSettingsResult1
End Sub
Public Sub StartLocationUpdates
flp.RequestLocationUpdates(CreateLocationRequest)
End Sub
Private Sub flp_LocationChanged (Location1 As Location)
CallSub2(Main, "Location_Changed", Location1)
Dim body As String = $"$2.5{Location1.Latitude} / $2.5{Location1.Longitude}"$
Dim n As Notification = CreateNotification(body)
n.Notify(nid)
Log(body)
Log(Location1.Latitude)
End Sub
Private Sub CreateLocationRequest As LocationRequest
Dim lr As LocationRequest
lr.Initialize
lr.SetInterval(0)
Return lr
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Service_Destroy
End Sub
Sub CreateNotification (Body As String) As Notification
Dim notification As Notification
notification.Initialize2(notification.IMPORTANCE_LOW)
notification.Icon = "icon"
notification.SetInfo("Location", Body, Main)
Return notification
End Sub