B4A=true Group=Default Group ModulesStructureVersion=1 Type=Service Version=9.9 @EndOfDesignText@ #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. Public rp As RuntimePermissions 'Para obtener permisos android 6+ Public FLP As FusedLocationProvider 'Para Tracker Dim ruta As String Dim reqManager As DBRequestManager Dim cmd As DBCommand Dim Timer1 As Timer Dim interval As Int = 60 '600 segs (10 mins) Dim UUC As Location Dim run As Int = 0 'ignore Dim devModel As String Dim lastLocUpdate As String = 0 Dim logger As Boolean = True End Sub Sub Service_Create 'This is the program entry point. 'This is a good place to load resources that are not specific to a single activity. ruta = File.DirInternal 'Ruta de la base de datos por defecto. If File.ExternalWritable Then ruta = rp.GetSafeDirDefaultExternal("") 'Si podemos escribir a la tarjeta, cambiamos la ruta. If Not(File.Exists(ruta, "gps_hist.db")) Then File.Copy(File.DirAssets, "gps_hist.db", ruta, "gps_hist.db") 'Si no existe el archivo de la base de datos, lo copiamos. If logger Then Log(ruta) CallSubDelayed(FirebaseMessaging, "SubscribeToTopics") 'Para FirebaseMessaging End Sub Sub Service_Start (StartingIntent As Intent) Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases. ' reqManager.Initialize(Me, "http://10.0.0.205:1782") reqManager.Initialize(Me, "http://keymon.lat:1782") Timer1.Initialize("Timer1", interval * 1000) Timer1.Enabled = True UUC.Initialize Subs.getPhnId StartService(Tracker) #if RELEASE logger = False #end if End Sub Private Sub Timer1_Tick ' ToastMessageShow("Timer",False) If logger Then Log("Next run " & DateTime.Time(DateTime.Now + interval * 1000)) ' Log($"|${Tracker.FLP.IsInitialized}|${Tracker.FLP.GetLastKnownLocation.IsInitialized}|"$)If DateTime.DateForm CallSub2(Tracker, "dameUltimaUbicacionConocida", UUC) 'Si ya pasaron mas de 15 minutos (900 segs) desde la ultima actualización, entonces mandamos UUC. If ((DateTime.now - lastLocUpdate)/1000) > (interval * 1.5) Then LogColor($"Mandamos ubicacion porque no se ha enviado en ${(interval * 1.5)} segs."$, Colors.red) Subs.mandaLocAServer(Tracker.FLP.GetLastKnownLocation, devModel) End If 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 End Sub