mirror of
https://github.com/cheveguerra/FLP_2.0.git
synced 2026-04-17 19:36:42 +00:00
29/9/23 - Correcciones en el envío de la ubicacion.
This commit is contained in:
234
FLP-ML.b4a
234
FLP-ML.b4a
@@ -1,234 +0,0 @@
|
||||
Build1=Default,flp2.chv.com
|
||||
File1=gps_hist.db
|
||||
File2=Layout.bal
|
||||
FileGroup1=Default Group
|
||||
FileGroup2=Default Group
|
||||
Group=Default Group
|
||||
Library1=administrator
|
||||
Library10=mlwifi400
|
||||
Library11=notificationlistener
|
||||
Library12=okhttputils2
|
||||
Library13=phone
|
||||
Library14=randomaccessfile
|
||||
Library15=reflection
|
||||
Library16=runtimepermissions
|
||||
Library17=sql
|
||||
Library18=replyauto
|
||||
Library2=byteconverter
|
||||
Library3=compressstrings
|
||||
Library4=core
|
||||
Library5=firebaseanalytics
|
||||
Library6=firebasenotifications
|
||||
Library7=fusedlocationprovider
|
||||
Library8=gps
|
||||
Library9=json
|
||||
ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="27"/>~\n~<supports-screens android:largeScreens="true" ~\n~ android:normalScreens="true" ~\n~ android:smallScreens="true" ~\n~ android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~CreateResourceFromFile(Macro, Themes.LightTheme)~\n~'End of default text.~\n~AddPermission(android.permission.ACCESS_FINE_LOCATION)~\n~AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)~\n~CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)~\n~CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)~\n~CreateResourceFromFile(Macro, FirebaseAnalytics.FirebaseAnalytics)~\n~CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)~\n~SetServiceAttribute(Tracker, android:foregroundServiceType, "location")~\n~~\n~AddApplicationText(<receiver android:name="anywheresoftware.b4a.objects.AdminReceiver2"~\n~ android:permission="android.permission.BIND_DEVICE_ADMIN">~\n~ <meta-data android:name="android.app.device_admin"~\n~ android:resource="@xml/device_admin" />~\n~ <intent-filter>~\n~ <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />~\n~ </intent-filter>~\n~</receiver>)~\n~~\n~CreateResource(xml, device_admin.xml,~\n~<device-admin xmlns:android="http://schemas.android.com/apk/res/android">~\n~ <uses-policies>~\n~ <limit-password />~\n~ <reset-password />~\n~ <force-lock />~\n~ </uses-policies>~\n~</device-admin>~\n~)~\n~AddPermission(android.permission.SEND_SMS)~\n~AddPermission(android.permission.RECEIVE_SMS)~\n~AddPermission(android.permission.READ_PHONE_STATE)~\n~AddPermission(android.permission.READ_CALL_LOG)~\n~AddApplicationText(~\n~<service android:name="b4a.jsaplication.com.br.ReplyAuto"~\n~ android:label="Mariana" android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">~\n~ <intent-filter><action android:name="android.service.notification.NotificationListenerService" /></intent-filter>~\n~ </service>)
|
||||
Module1=DBRequestManager
|
||||
Module2=FirebaseMessaging
|
||||
Module3=Mods
|
||||
Module4=NotificationService
|
||||
Module5=Starter
|
||||
Module6=Subs
|
||||
Module7=Tracker
|
||||
NumberOfFiles=2
|
||||
NumberOfLibraries=18
|
||||
NumberOfModules=7
|
||||
Version=12.5
|
||||
@EndOfDesignText@
|
||||
#Region Project Attributes
|
||||
#ApplicationLabel: FLP 2.0
|
||||
#VersionCode: 1
|
||||
#VersionName: 3.09.27
|
||||
'SupportedOrientations possible values: unspecified, landscape or portrait.
|
||||
#SupportedOrientations: unspecified
|
||||
#CanInstallToExternalStorage: False
|
||||
' #AdditionalJar: com.android.support:support-v4
|
||||
#AdditionalJar: com.google.android.gms:play-services-location
|
||||
#BridgeLogger:True
|
||||
'###########################################################################################################
|
||||
'###################### PULL #############################################################
|
||||
'Ctrl + click ide://run?file=%WINDIR%\System32\cmd.exe&Args=/c&Args=git&Args=pull
|
||||
'###########################################################################################################
|
||||
'###################### PUSH #############################################################
|
||||
'Ctrl + click ide://run?file=%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe&Args=github&Args=..\..\
|
||||
'###########################################################################################################
|
||||
'###################### PUSH TORTOISE GIT #########################################################
|
||||
'Ctrl + click ide://run?file=%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe&Args=TortoiseGitProc&Args=/command:commit&Args=/path:"./../"&Args=/closeonend:2
|
||||
'###########################################################################################################
|
||||
#End Region
|
||||
|
||||
#Region Activity Attributes
|
||||
#FullScreen: False
|
||||
#IncludeTitle: 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 wifi As MLwifi
|
||||
Dim wifiS As MLScan
|
||||
Public manager As AdminManager
|
||||
' Dim ruta As String
|
||||
Dim fechaRuta As String
|
||||
Dim laUbicacion As Location
|
||||
End Sub
|
||||
|
||||
Sub Globals
|
||||
'These global variables will be redeclared each time the activity is created.
|
||||
Private b_pong As Button
|
||||
Private et_id As EditText
|
||||
Private b_guardarId As Button
|
||||
Private l_coords As Label
|
||||
Dim l_lastUpdate As Label
|
||||
Private l_id As Label
|
||||
End Sub
|
||||
|
||||
Sub Activity_Create(FirstTime As Boolean)
|
||||
Activity.LoadLayout("Layout")
|
||||
' ruta = File.DirInternal
|
||||
Subs.getPhnId
|
||||
et_id.Text = Starter.devModel.trim
|
||||
getSSID
|
||||
b_pong.Left = Round(Activity.Width/2)-(b_pong.Width/2)
|
||||
l_id.Left = (Activity.Width / 2) - (l_id.Width / 2)
|
||||
l_lastUpdate.Left = (Activity.Width / 2) - (l_lastUpdate.Width / 2)
|
||||
b_guardarId.Left = (Activity.Width / 2) - (b_guardarId.Width / 2)
|
||||
et_id.Left = (Activity.Width / 2) - (et_id.Width / 2)
|
||||
End Sub
|
||||
|
||||
Sub Activity_Resume
|
||||
chkPermisosUbicacion 'Permisos de ubicacion para Tracker
|
||||
chkPermisosAlmacenamientoExterno
|
||||
Subs.getPhnId
|
||||
et_id.Text = Starter.devModel.Trim
|
||||
getSSID
|
||||
getAdminRights
|
||||
l_lastUpdate.Text = Starter.lastLocUpdate
|
||||
' ruta = File.DirInternal
|
||||
If Not(CheckNotificationAccess) Then
|
||||
Msgbox2Async($"Se necesita acceso a las notificaciones, haga clic en "Aceptar" y en la siguiente pantalla permita el acceso a la aplicación "${Application.LabelName}"."$, "Permisos necesarios", "Aceptar", "Cancelar", "", Null, True)
|
||||
Wait For Msgbox_Result (resultado As Int)
|
||||
If resultado = DialogResponse.POSITIVE Then
|
||||
Dim In As Intent
|
||||
In.Initialize("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS", "")
|
||||
StartActivity(In)
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub Activity_Pause (UserClosed As Boolean)
|
||||
|
||||
End Sub
|
||||
|
||||
Sub b_pong_Click
|
||||
CallSubDelayed(Tracker, "StartFLP")
|
||||
If laUbicacion.IsInitialized Then Subs.mandaLocAServer(laUbicacion, Starter.devModel.Trim)
|
||||
Dim params As Map = CreateMap("topic": FirebaseMessaging.Sprvsr,"title":"Prueba Trckr", "body":"Prueba Trckr", "d":Starter.devModel, "t":"pong")
|
||||
CallSubDelayed2(FirebaseMessaging, "SendMessage",params)
|
||||
If Starter.logger Then Log("Start wifi scan")
|
||||
wifiS.startscan("WiFi", True)
|
||||
Wait For WiFi_ScanDone (Results() As String, Count As Int)
|
||||
End Sub
|
||||
|
||||
Sub b_pong_LongClick
|
||||
' copiaDB
|
||||
CallSubDelayed(Tracker, "StartFLP")
|
||||
If laUbicacion.IsInitialized Then Subs.mandaLocAServer(laUbicacion, Starter.devModel.Trim)
|
||||
Dim params As Map = CreateMap("topic": FirebaseMessaging.Sprvsr,"title":"Prueba Trckr", "body":l_coords.Text, "d":Starter.devModel, "t":"au")
|
||||
CallSubDelayed2(FirebaseMessaging, "SendMessage",params)
|
||||
If Starter.logger Then Log("Start wifi scan")
|
||||
wifiS.startscan("WiFi", True)
|
||||
Wait For WiFi_ScanDone (Results() As String, Count As Int)
|
||||
End Sub
|
||||
|
||||
Sub chkPermisosAlmacenamientoExterno
|
||||
Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
|
||||
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
|
||||
If Result Then
|
||||
If Starter.logger Then Log("Permisos de almacenamiento externo OK")
|
||||
Else
|
||||
' ToastMessageShow("SIN permisos de almacenamiento externo", True)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub chkPermisosUbicacion
|
||||
If Starter.logger Then Log("Revisamos permisos de ubicación.")
|
||||
Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
|
||||
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
|
||||
If Result Then
|
||||
StartService(Tracker)
|
||||
If Starter.logger Then Log("Start Tracker")
|
||||
Else
|
||||
' ToastMessageShow("SIN permisos de ubicacion", True)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub getSSID
|
||||
If wifi.isWifiConnected Then
|
||||
Subs.ssid = wifi.WifiSSID
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub getAdminRights
|
||||
If manager.Enabled = False Then
|
||||
manager.Enable("Please enable in order to get access to the secured server.")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Sub wifiScanned_ScanDone
|
||||
' Log("//////////////////////////////wifi_conected_result")
|
||||
' ToastMessageShow("Wifi_ConnectionResult",True)
|
||||
' If wifi.isWifiConnected Then
|
||||
' ssid = wifi.WifiSSID
|
||||
' End If
|
||||
'End Sub
|
||||
|
||||
Sub copiaDB
|
||||
' Log("ruta="&ruta)
|
||||
' Log("File.DirInternal="&File.DirInternal)
|
||||
' Log("File.DirRootExternal="&File.DirRootExternal)
|
||||
' Log("File.DirDefaultExternal="&File.DirDefaultExternal)
|
||||
' Log(Starter.rp.GetSafeDirDefaultExternal(""))
|
||||
' Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
|
||||
' Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
|
||||
' If Result Then
|
||||
' If Starter.logger Then Log("Tenemos permisos de escritura.")
|
||||
' File.Copy(Starter.ruta , "gps_hist.db", File.DirDefaultExternal, "gps_hist.db")
|
||||
' If Starter.logger Then Log($"DB escrita a ${File.DirDefaultExternal}"$)
|
||||
' ToastMessageShow($"DB escrita a ${File.DirDefaultExternal}"$, True)
|
||||
' End If
|
||||
End Sub
|
||||
|
||||
Private Sub b_guardarId_Click
|
||||
If et_id.Text.Length > 2 Then 'Si tenemos valor para ID
|
||||
File.WriteString(File.DirInternal, "phnId.txt", et_id.Text.trim) 'Sobreescribimos archivo IdPersonal.txt con ID
|
||||
Starter.devModel = et_id.Text.Trim
|
||||
If Starter.logger Then Log("Tenemos ID: "& et_id.Text.Trim & " "&File.DirInternal&"/phnId.txt sobreescrito")
|
||||
Else If et_id.Text.Length < 3 Then ' Si no tenemos valor, lo leemos de IdPersonal.txt
|
||||
Dim s As String = File.ReadString(File.DirInternal, "phnId.txt")
|
||||
Starter.devModel = s
|
||||
If Starter.logger Then Log("Leemos id de "&File.DirInternal&"/phnId.txt")
|
||||
et_id.Text = Starter.devModel.Trim
|
||||
If Starter.logger Then Log(Starter.devModel.Trim)
|
||||
End If
|
||||
If laUbicacion.IsInitialized Then Subs.mandaLocAServer(laUbicacion, Starter.devModel.Trim)
|
||||
End Sub
|
||||
|
||||
Sub ponCoords
|
||||
l_coords.left = (Activity.Width/2) - (l_coords.Width/2)
|
||||
l_coords.Text = $"${Starter.UUC.Latitude},${Starter.UUC.Longitude}"$
|
||||
End Sub
|
||||
|
||||
'Revisa si la aplicación tiene permiso para acceder a las notificaciones.
|
||||
Sub CheckNotificationAccess As Boolean
|
||||
Dim ph As Phone
|
||||
Dim nstr, pstr As String
|
||||
Dim r As Reflector
|
||||
pstr = r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
|
||||
nstr = ph.GetSettings("enabled_notification_listeners")
|
||||
Return nstr.Contains(pstr)
|
||||
End Sub
|
||||
|
||||
Sub actualizaLabelUU
|
||||
l_lastUpdate.Text = Subs.fechaKMT(Starter.lastLocUpdate)
|
||||
End Sub
|
||||
@@ -1,27 +0,0 @@
|
||||
ModuleBookmarks0=
|
||||
ModuleBookmarks1=
|
||||
ModuleBookmarks2=
|
||||
ModuleBookmarks3=
|
||||
ModuleBookmarks4=
|
||||
ModuleBookmarks5=
|
||||
ModuleBookmarks6=
|
||||
ModuleBookmarks7=
|
||||
ModuleBreakpoints0=
|
||||
ModuleBreakpoints1=
|
||||
ModuleBreakpoints2=
|
||||
ModuleBreakpoints3=
|
||||
ModuleBreakpoints4=
|
||||
ModuleBreakpoints5=
|
||||
ModuleBreakpoints6=
|
||||
ModuleBreakpoints7=
|
||||
ModuleClosedNodes0=12,13
|
||||
ModuleClosedNodes1=
|
||||
ModuleClosedNodes2=7
|
||||
ModuleClosedNodes3=1
|
||||
ModuleClosedNodes4=
|
||||
ModuleClosedNodes5=2,3
|
||||
ModuleClosedNodes6=2,3,4,5,6,7,8,9,10,11,12,13
|
||||
ModuleClosedNodes7=9,11
|
||||
NavigationStack=Starter,Timer1_Tick,55,6,NotificationService,NotiMon_NotificationPosted,81,6,Tracker,StopFLP,128,0,FirebaseMessaging,fm_MessageArrived,82,0,FirebaseMessaging,mandamosLoc,152,0,Tracker,dameUltimaUbicacionConocida,112,1,Tracker,flp_LocationChanged,142,0,Main,b_pong_Click,86,0,Visual Designer,Layout.bal,-100,1,Main,b_pong_LongClick,99,3
|
||||
SelectedBuild=0
|
||||
VisibleModules=5,2,7,3,6,4
|
||||
@@ -72,8 +72,12 @@ Sub Service_Destroy
|
||||
End Sub
|
||||
|
||||
Sub NotiMon_NotificationPosted (SBN As StatusBarNotification)
|
||||
If Not(Tracker.FLP.IsInitialized) Then StartService(Tracker) 'Si el servicio no esta corriendo, lo iniciamos.
|
||||
If Not(Tracker.FLP.IsInitialized) Then
|
||||
StartService(Tracker) 'Si el servicio no esta corriendo, lo iniciamos.
|
||||
Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${Starter.devModel}', 'Recibimos notificación, Tracker apagado, INICIANDOLO!!', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
End If
|
||||
Private logger As Boolean = True
|
||||
If Starter.logger Then LogColor(SBN.PackageName & " - " & SBN.Message, Colors.blue)
|
||||
' Log("-= Notificacion recibida =-")
|
||||
If SBN.PackageName = "com.whatsapp" Then
|
||||
' If logger Then LogColor(SBN.PackageName, Colors.Red)
|
||||
@@ -84,9 +88,10 @@ Sub NotiMon_NotificationPosted (SBN As StatusBarNotification)
|
||||
' Si recibimos un mensaje con la palabra "donde", "Donde" o "bien", entonces mandamos la última ubicación conocida.
|
||||
If SBN.Message.Contains("donde") Or SBN.Message.Contains("Donde") Or SBN.Message.Contains("bien") Then 'Si el mensaje contiene "#NS" y tiene un segundo parametro ...
|
||||
If esMensajeWAValido(SBN) Then
|
||||
CallSubDelayed(Tracker, "StartFLP")
|
||||
Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${Starter.devModel}', 'Recibimos notificación, iniciamos StartFLP y guardamos UUC', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
CallSubDelayed2(Tracker, "dameUltimaUbicacionConocida", Starter.UUC)
|
||||
Log("Mandamos a Server")
|
||||
CallSubDelayed(Tracker, "StartFLP")
|
||||
If Starter.logger Then Log("Mandamos a Server")
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
15
Starter.bas
15
Starter.bas
@@ -24,7 +24,7 @@ Sub Process_Globals
|
||||
Dim devModel As String
|
||||
Dim lastLocUpdate As String = 0
|
||||
Dim logger As Boolean = True
|
||||
Dim FLPStatus As String
|
||||
' Dim FLPStatus As String
|
||||
End Sub
|
||||
|
||||
Sub Service_Create
|
||||
@@ -33,6 +33,8 @@ Sub Service_Create
|
||||
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 Subs.gps_hist.IsInitialized = False Then Subs.gps_hist.Initialize(ruta, "gps_hist.db", True)
|
||||
Subs.gps_hist.ExecNonQuery("CREATE TABLE IF NOT EXISTS BITACORA(RUTA TEXT, TEXTO TEXT, FECHA TEXT)")
|
||||
If logger Then Log(ruta)
|
||||
CallSubDelayed(FirebaseMessaging, "SubscribeToTopics") 'Para FirebaseMessaging
|
||||
End Sub
|
||||
@@ -45,7 +47,9 @@ Sub Service_Start (StartingIntent As Intent)
|
||||
Timer1.Enabled = True
|
||||
UUC.Initialize
|
||||
Subs.getPhnId
|
||||
Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${devModel}', 'Starter - Service_Start', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
StartService(Tracker)
|
||||
StartReceiverAt(Tracker, DateTime.Now + 30 * DateTime.TicksPerMinute, True)
|
||||
#if RELEASE
|
||||
logger = False
|
||||
#end if
|
||||
@@ -53,14 +57,15 @@ End Sub
|
||||
|
||||
Private Sub Timer1_Tick
|
||||
CallSubDelayed(Tracker, "StartFLP")
|
||||
Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${devModel}', 'TimerTick - tiempo trans: ${((DateTime.now - lastLocUpdate)/1000)}', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
If logger Then Log("Next run " & DateTime.Time(DateTime.Now + interval * 1000))
|
||||
' Log($"|${Tracker.FLP.IsInitialized}|${Tracker.FLP.GetLastKnownLocation.IsInitialized}|"$)If DateTime.DateForm
|
||||
|
||||
'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 "Ultima Ubicacion Conocida" porque no se ha enviado en ${(interval * 1.5)} segs."$, Colors.red)
|
||||
CallSub2(Tracker, "dameUltimaUbicacionConocida", UUC)
|
||||
If Tracker.FLP.IsInitialized Then Subs.mandaLocAServer(Tracker.FLP.GetLastKnownLocation, devModel)
|
||||
If logger Then LogColor($"Mandamos "Ultima Ubicacion Conocida" porque no se ha enviado en ${(interval * 1.5)} segs."$, Colors.red)
|
||||
Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${devModel}', 'TimerTick, Tiempo mayor a 1.5, iniciamos StartFLP y guardamos UUC', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
CallSubDelayed2(Tracker, "dameUltimaUbicacionConocida", UUC)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
@@ -74,5 +79,5 @@ Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
|
||||
End Sub
|
||||
|
||||
Sub Service_Destroy
|
||||
|
||||
Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${devModel}', 'Starter - Service destroyed')"$)
|
||||
End Sub
|
||||
|
||||
8
Subs.bas
8
Subs.bas
@@ -119,7 +119,7 @@ Sub deleteGPS_DB
|
||||
' gps_hist.ExecQuery
|
||||
gps_hist.ExecNonQuery("delete from RUTA_GPS")
|
||||
gps_hist.ExecNonQuery("vacuum;")
|
||||
Log("RUTA_GPS borrada")
|
||||
If Starter.logger Then Log("RUTA_GPS borrada")
|
||||
End Sub
|
||||
|
||||
Sub borramosArchivoGPS
|
||||
@@ -134,7 +134,7 @@ Sub revisaBD
|
||||
' Starter.ruta = File.DirInternal
|
||||
If File.Exists(Starter.ruta, "gps_hist.db") = False Then
|
||||
File.Copy(File.DirAssets, "gps_hist.db", Starter.ruta, "gps_hist.db")
|
||||
Log("No existe gps_hist, copiamos gps_hist.db")
|
||||
If Starter.logger Then Log("No existe gps_hist, copiamos gps_hist.db")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
@@ -174,7 +174,7 @@ Sub mandaLocAServer(loc As Location, id As String)
|
||||
Starter.cmd.Name = "guardaDatos"
|
||||
Starter.cmd.Parameters = Array As Object(fechaKMT(DateTime.Now), id, fechaKMT(DateTime.Now), $"${loc.Latitude},${loc.Longitude},${loc.Accuracy},${loc.AccuracyValid},${loc.Speed},${loc.SpeedValid}"$, "Coords")
|
||||
' If Starter.logger Then
|
||||
Log($"Mandamos loc a server: ${fechaKMT(DateTime.Now)}|${id}|${fechaKMT(DateTime.Now)}|${loc.Latitude},${loc.Longitude}|Coords"$)
|
||||
If Starter.logger Then Log($"Mandamos loc a server: ${fechaKMT(DateTime.Now)}|${id}|${fechaKMT(DateTime.Now)}|${loc.Latitude},${loc.Longitude}|Coords"$)
|
||||
' End If
|
||||
Starter.reqManager.ExecuteCommand(Starter.cmd,"guardaDatos")
|
||||
End Sub
|
||||
@@ -185,4 +185,4 @@ Sub ConvertMillisecondsToString(t As Long) As String 'ignore
|
||||
minutes = (t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute
|
||||
seconds = (t Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond
|
||||
Return $"$1.0{hours}:$2.0{minutes}:$2.0{seconds}"$
|
||||
End Sub
|
||||
End Sub
|
||||
|
||||
55
Tracker.bas
55
Tracker.bas
@@ -39,7 +39,7 @@ Sub Process_Globals
|
||||
'Para FusedLocationProvider (2 lineas)
|
||||
Public FLP As FusedLocationProvider
|
||||
Private flpStarted As Boolean
|
||||
Dim minAccuracy As Int = 30
|
||||
Dim minAccuracy As Int = 50
|
||||
End Sub
|
||||
|
||||
Sub Service_Create
|
||||
@@ -50,6 +50,7 @@ Sub Service_Create
|
||||
lock.PartialLock
|
||||
StartFLP
|
||||
If Starter.logger Then Log("FLP initialized")
|
||||
Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${Starter.devModel}', 'Iniciamos Tracker', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
End Sub
|
||||
|
||||
Sub flp_ConnectionSuccess
|
||||
@@ -67,6 +68,7 @@ Sub Service_Start (StartingIntent As Intent)
|
||||
Service.StartForeground(nid, Subs.CreateNotification("..."))
|
||||
Track
|
||||
StartServiceAt(Me, DateTime.Now + 10 * DateTime.TicksPerMinute, True)
|
||||
Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${starter.devModel}', 'Tracker - Service_Start', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
End Sub
|
||||
|
||||
Public Sub Track
|
||||
@@ -81,14 +83,14 @@ Public Sub Track
|
||||
End Sub
|
||||
|
||||
Public Sub StartFLP
|
||||
Log("StartFLP - flpStarted="&flpStarted)
|
||||
' Log("StartFLP - flpStarted="&flpStarted)
|
||||
Do While FLP.IsConnected = False
|
||||
Sleep(500)
|
||||
Log("sleeping")
|
||||
Loop
|
||||
' If flpStarted = False Then
|
||||
Log("RequestLocationUpdates")
|
||||
Starter.FLPStatus = "Searching" : LogColor("FLP Searching", Colors.blue)
|
||||
' Log("RequestLocationUpdates")
|
||||
' Starter.FLPStatus = "Searching" : LogColor("FLP Searching", Colors.blue)
|
||||
FLP.RequestLocationUpdates(CreateLocationRequest) 'Buscamos ubicacion
|
||||
flpStarted = True
|
||||
' End If
|
||||
@@ -96,7 +98,7 @@ End Sub
|
||||
|
||||
Private Sub CreateLocationRequest As LocationRequest
|
||||
' Log("CreateLocationRequest")
|
||||
Starter.FLPStatus = "Searching" : LogColor("FLP Searching", Colors.blue)
|
||||
' Starter.FLPStatus = "Searching" : LogColor("FLP Searching", Colors.blue)
|
||||
Dim lr As LocationRequest
|
||||
lr.Initialize
|
||||
lr.SetInterval(30000) 'Intervalo deseado para actualizaciones de ubicacion en milisegundos
|
||||
@@ -106,23 +108,16 @@ Private Sub CreateLocationRequest As LocationRequest
|
||||
Return lr
|
||||
End Sub
|
||||
|
||||
Sub dameUltimaUbicacionConocida(lastLocation As Location)
|
||||
Sub dameUltimaUbicacionConocida(lastLocation As Location) '
|
||||
If Starter.logger Then LogColor("dameUltimaUbicacionConocida", Colors.Magenta)
|
||||
If FLP.GetLastKnownLocation.IsInitialized Then 'Mandamos ultima ubicacion guardada
|
||||
If Starter.logger Then Log("This accuracy: " & FLP.GetLastKnownLocation.Accuracy)
|
||||
If Starter.logger Then Log("This distance to previous: " & FLP.GetLastKnownLocation.DistanceTo(lastLocation))
|
||||
Dim coords As String = FLP.GetLastKnownLocation.Latitude&","&FLP.GetLastKnownLocation.Longitude&","&Subs.formatoFecha(FLP.GetLastKnownLocation.Time)
|
||||
If FLP.GetLastKnownLocation.Accuracy < minAccuracy And FLP.GetLastKnownLocation.DistanceTo(lastLocation) > 25 Then
|
||||
Starter.UUC = FLP.GetLastKnownLocation
|
||||
Subs.mandaLocAServer(FLP.GetLastKnownLocation, Starter.devModel)
|
||||
If Starter.logger Then Log("Mandamos GetLastKnownLocation : "&DateTime.Time(FLP.GetLastKnownLocation.Time))
|
||||
CallSubDelayed2(FirebaseMessaging,"mandamosLoc",coords)
|
||||
Log($"UUC: ${Starter.UUC.Latitude},${Starter.UUC.Longitude}"$)
|
||||
End If
|
||||
' Log($"ultima actualizacion: ${Starter.lastLocUpdate}"$)
|
||||
' Log($"${DateTime.now} - ${Starter.lastLocUpdate} = ${(DateTime.Now - Starter.lastLocUpdate)/1000}"$)
|
||||
' Log("||" & Subs.ConvertMillisecondsToString((DateTime.Now - Starter.lastLocUpdate)))
|
||||
End If
|
||||
' Subs.gps_hist.ExecNonQuery("CREATE TABLE IF NOT EXISTS RUTA_GPS(FECHA INTEGER, LAT TEXT, LON TEXT)")
|
||||
If Starter.logger Then Log("This accuracy: " & Starter.UUC.Accuracy)
|
||||
Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${Starter.devModel}', 'Enviamos UUC - Acc: ${Starter.UUC.Accuracy}, Time:${Starter.UUC.Time}', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
Dim coords As String = Starter.UUC.Latitude & ","&Starter.UUC.Longitude & ","&Subs.formatoFecha(Starter.UUC.Time)
|
||||
Subs.mandaLocAServer(Starter.UUC, Starter.devModel)
|
||||
CallSubDelayed2(FirebaseMessaging,"mandamosLoc",coords)
|
||||
If Starter.logger Then Log("Mandamos GetLastKnownLocation : "&DateTime.Time(FLP.GetLastKnownLocation.Time))
|
||||
If Starter.logger Then Log($"UUC: ${Starter.UUC.Latitude},${Starter.UUC.Longitude}"$)
|
||||
End Sub
|
||||
|
||||
Public Sub StopFLP
|
||||
@@ -134,7 +129,9 @@ Public Sub StopFLP
|
||||
End Sub
|
||||
|
||||
Sub flp_LocationChanged (Location1 As Location)
|
||||
Starter.FLPStatus = "Location changed" : LogColor("Location changed", Colors.blue)
|
||||
' Starter.FLPStatus = "Location changed" : LogColor("Location changed", Colors.blue)
|
||||
Dim el_texto As String = ""
|
||||
Starter.UUC = Location1
|
||||
If Not(Starter.Timer1.Enabled) Then Starter.Timer1.Enabled = True : Log("timer enabled")
|
||||
If Starter.logger Then LogColor("FLP_LocationChanged", Colors.Red)
|
||||
' ToastMessageShow("FLP_LocationChanged", False)
|
||||
@@ -146,10 +143,17 @@ Sub flp_LocationChanged (Location1 As Location)
|
||||
If Starter.logger Then Log(Location1)
|
||||
If Starter.logger Then Log(Location1.Accuracy&" - "&Location1.AccuracyValid)
|
||||
' solo mandamos la ubicacion si la precision es dentro de XX mts
|
||||
If Location1.Accuracy < minAccuracy Then CallSubDelayed2(FirebaseMessaging,"mandamosLoc", coords)
|
||||
If Location1.Accuracy < minAccuracy Then Starter.UUC = Location1
|
||||
If Location1.Accuracy < minAccuracy Then Subs.mandaLocAServer(Location1, Starter.devModel)
|
||||
el_texto = $"LocChange - Coords NO enviadas (Acc:${Location1.Accuracy})."$
|
||||
If Location1.Accuracy < minAccuracy Then
|
||||
CallSubDelayed2(FirebaseMessaging,"mandamosLoc", coords)
|
||||
Subs.mandaLocAServer(Location1, Starter.devModel)
|
||||
Dim coords As String = Location1.Latitude&","&Location1.Longitude&","&Subs.formatoFecha(Location1.Time)
|
||||
CallSubDelayed2(FirebaseMessaging,"mandamosLoc",coords)
|
||||
el_texto = $"LocChange - Coords enviadas (Acc:${Location1.Accuracy})."$
|
||||
End If
|
||||
If Starter.logger Then Log("Loc changed : "&Location1.Latitude&","&Location1.Longitude&"|"&Starter.devModel&"|")
|
||||
Subs.gps_hist.ExecNonQuery("CREATE TABLE IF NOT EXISTS BITACORA(RUTA TEXT, TEXTO TEXT, FECHA TEXT)")
|
||||
Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${Starter.devModel}', '${el_texto}', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
CallSubDelayed(Main, "ponCoords")
|
||||
End Sub
|
||||
|
||||
@@ -159,4 +163,5 @@ Sub Service_Destroy
|
||||
End If
|
||||
Tracking = False
|
||||
lock.ReleasePartialLock
|
||||
Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${Starter.devModel}', 'Tracker - Service_Destroy', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
End Sub
|
||||
|
||||
Reference in New Issue
Block a user