#Region Service Attributes
#StartAtBoot: True
' Versione 1C ok
#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 timer1 As Timer
Private nid As Int = 1
Private GPS As GPS
Private Tracking As Boolean
Private LastUpdateTime As Long
Private lock As PhoneWakeState
Dim hc As OkHttpClient
Dim Geocoder1 As Geocoder
'Dim anna As String
'Dim filippo As String
Dim risultatolivello As String
Dim p As Phone
End Sub
Sub Service_Create
risultatolivello = Main.livellovolume
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS 'we are handling it ourselves
GPS.Initialize("gps")
lock.PartialLock
hc.Initialize("hc")
timer1.Initialize("timer1",2000)
Geocoder1.Initialize("it")
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
Log("sono su keypress")
If KeyCode = KeyCodes.KEYCODE_VOLUME_UP Then
Log("Up")
p.SetVolume(p.VOLUME_MUSIC, risultatolivello, False)
Return True
End If
If KeyCode = KeyCodes.KEYCODE_VOLUME_DOWN Then
Log("Down")
p.SetVolume(p.VOLUME_MUSIC, risultatolivello, False)
Return True
End If
End Sub
Sub Service_Start (StartingIntent As Intent)
Log(p.GetVolume(p.VOLUME_MUSIC))
'p.SetMute(p.VOLUME_MUSIC,False)
p.SetVolume(p.VOLUME_MUSIC, risultatolivello, False)
timer1.Enabled=True
Service.StartForeground(nid, CreateNotification("..."))
Track
StartServiceAtExact(Me, DateTime.Now + 25 * DateTime.TicksPerMinute, True)
End Sub
Sub timer1_Tick
Log(risultatolivello)
p.SetVolume(p.VOLUME_MUSIC, risultatolivello, False)
Track
StartServiceAtExact(Me, DateTime.Now + 25 * DateTime.TicksPerMinute, True)
End Sub
Public Sub Track
If Tracking Then Return
If Starter.rp.Check(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION) = False Then
Log("No permission")
Return
End If
GPS.Start(0, 0)
Tracking = True
End Sub
Sub GPS_LocationChanged (Location1 As Location)
'anna = Location1.Latitude
'filippo = Location1.Longitude
If DateTime.Now > LastUpdateTime + 3 * DateTime.TicksPerSecond Then
Dim n As Notification = CreateNotification($"$2.5{Location1.Latitude} / $2.5{Location1.Longitude}"$)
n.Notify(nid)
LastUpdateTime = DateTime.Now
End If
End Sub
Sub CreateNotification (Body As String) As Notification
Dim notification As Notification
notification.Initialize2(notification.IMPORTANCE_LOW)
notification.Icon = "icon"
notification.Sound=False
notification.Vibrate=False
notification.SetInfo("OK", Body, Main)
Return notification
End Sub
Sub Service_Destroy
If Tracking Then
GPS.Stop
End If
Tracking = False
lock.ReleasePartialLock
End Sub