#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim lock As PhoneWakeState
Dim LatLonOud As Location
Dim GPSTrack As FusedLocationProvider
Dim Route As List
Dim RouteTijd As List
Dim OpnemenRoute As Boolean
End Sub
Sub Service_Create
If(LatLonOud.IsInitialized=False) Then LatLonOud.Initialize
If(Route.IsInitialized=False) Then Route.Initialize
If(RouteTijd.IsInitialized=False) Then RouteTijd.Initialize
If(GPSTrack.IsInitialized=False) Then GPSTrack.Initialize("GPSTrack")
'Service.AutomaticForegroundNotification=RemoveIcon
Service.AutomaticForegroundMode=Service.AUTOMATIC_FOREGROUND_NEVER
lock.PartialLock
End Sub
Sub Service_Start (StartingIntent As Intent)
Service.StartForeground(999,RemoveIcon)
StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerMinute, True)
Track
End Sub
Sub Service_TaskRemoved
'This event will be raised when the user removes the app from the recent apps list.
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
Log("Destroyed2")
If GPSTrack.IsConnected Then
GPSTrack.Disconnect
Route.Clear
RouteTijd.Clear
End If
'lock.ReleasePartialLock
End Sub
Public Sub Track
Log("GPSTrack is ON")
If (GPSTrack.IsConnected) Then Return
If (Starter.rp.Check(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)=False) Then
Log("No permission")
Return
Else
GPSTrack.Connect
End If
End Sub
Sub GPSTrack_ConnectionSuccess
Dim LocationRequest1 As LocationRequest
LocationRequest1.Initialize
LocationRequest1.SetInterval(20000) '1000 is 1 seconde
LocationRequest1.SetPriority(LocationRequest1.Priority.PRIORITY_BALANCED_POWER_ACCURACY) '.PRIORITY_HIGH_ACCURACY)
Dim LocationSettingsRequestBuilder1 As LocationSettingsRequestBuilder
LocationSettingsRequestBuilder1.Initialize
LocationSettingsRequestBuilder1.AddLocationRequest(LocationRequest1)
GPSTrack.CheckLocationSettings(LocationSettingsRequestBuilder1.Build)
GPSTrack.RequestLocationUpdates(LocationRequest1)
End Sub
Sub GPSTrack_LocationSettingsChecked(LocationSettingsResult1 As LocationSettingsResult)
End Sub
Sub RemoveIcon As Notification
Dim ic As Notification
ic.Initialize2(ic.IMPORTANCE_LOW)
ic.Icon="empty"
ic.Sound=False
ic.SetInfo("","",Null)
Return ic
End Sub
Sub GPSTrack_LocationChanged(Location1 As Location)
Dim HTTPLocatie As HttpJob
Dim DatumTijd As String
If(Starter.GPSLoc) Then
If(Location1.DistanceTo(LatLonOud)/1000>0.1) Then '100m
Log("GPS verzonden")
HTTPLocatie.Initialize("",Me)
HTTPLocatie.Download(......&lat="&Location1.Latitude&"&lon="&Location1.Longitude)
Wait For (HTTPLocatie) JobDone(HTTPLocatie As HttpJob)
If(HTTPLocatie.Success = True) Then
Else
End If
HTTPLocatie.Release
End If
End If
If(OpnemenRoute) Then
If(Location1.DistanceTo(LatLonOud)/1000>0.5) Then '500m
DateTime.DateFormat="dd-MM-yyyy"
DatumTijd=DateTime.Date(DateTime.Now)&"/"&DateTime.Time(DateTime.Now)
Route.Add(Location1)
RouteTijd.Add(DatumTijd)
End If
End If
LatLonOud=Location1
End Sub