B4A=true Group=Default Group ModulesStructureVersion=1 Type=Service Version=10.5 @EndOfDesignText@ Sub Process_Globals Private fm As FirebaseMessaging Dim db As SQL End Sub Sub Service_Create fm.Initialize("fm") db = Subs.dbInit End Sub Public Sub SubscribeToTopics fm.SubscribeToTopic("Trckr") 'Global (you can subscribe to more topics) fm.SubscribeToTopic("Sprvsr") fm.SubscribeToTopic("Sprv-ML") fm.SubscribeToTopic("Sprv-This") fm.SubscribeToTopic("Sprv-Cedex") fm.SubscribeToTopic("Sprv-GunaReparto") fm.SubscribeToTopic("Sprv-Durakelo") ' Log(fm.token) End Sub Sub Service_Start (StartingIntent As Intent) If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent) 'Sleep(0) 'Service.StopAutomaticForeground 'remove if not using B4A v8+. End Sub Sub fm_MessageArrived (Message As RemoteMessage) If Starter.logger Then Log($"Pusher - Mensaje recibido: ${Message.GetData}"$) ' Log($"Message data: ${Message.GetData}"$) 'Si recibimos Pong, lo agregamos a la lista de dispositivos activos If Message.GetData.ContainsKey("t") And Message.GetData.Get("t") = "pong" Then Log("Pusher - Recibimos pong "&Message.GetData.Get("d")) If Main.dispositivos.ContainsKey(Message.GetData.Get("d")) Then Dim dMap As Map = Main.dispositivos.Get(Message.GetData.Get("d")) Dim dispData As Map = dMap Else Dim dispData As Map = CreateMap("coords": "0,0", "d": Message.GetData.Get("d"),"v": Message.GetData.Get("v"), "w": Message.GetData.Get("w")) End If ' Log("** "&dispData) Main.dispositivos.Put(Message.GetData.Get("d"), dispData) End If 'Si el mensaje es de ubicacion recibida If Message.GetData.ContainsKey("t") And (Message.GetData.Get("t") = "u" Or Message.GetData.Get("t") = "au") Then If Starter.logger Then Log("Pusher - Recibimos ubicacion") Private ubi As Location ' Log("Llamamos UbicacionRecibida") If Message.GetData.Get("t") = "au" Or Message.GetData.Get("t") = "u" Then ' ToastMessageShow("Ubicacion recibida:"&Message.GetData.Get("body"),False) Private coords() As String = Regex.split(",", Message.GetData.Get("body")) ubi.Initialize If Message.GetData.Get("body") <> "" Then ubi.Latitude = coords(0) ubi.Longitude = coords(1) Else ubi.Latitude = 0 ubi.Longitude = 0 End If ' ubi.Longitude = coords(1) Private c As Cursor = db.ExecQuery("select * from geocercas") 'Traemos las geocercas Private estaGC As Location Private enGoecerca As Boolean = False Private nuevoEnGoecerca As Boolean = False If c.RowCount > 0 Then For i = 0 To c.RowCount - 1 c.Position = i estaGC.Initialize estaGC.Latitude = c.GetString("lat") estaGC.Longitude = c.GetString("lon") ' Log(ubi & "|" & estaGC) ' Log(ubi.DistanceTo(estaGC)) If ubi.DistanceTo(estaGC) < 300 Then 'Revisamos si la ubicaccion recibida esta dentro de alguna geocerca. ' ToastMessageShow($"Dentro de ${c.GetString("nombre")}"$, False) enGoecerca = True If Not(Starter.dentroDeGeocerca.ContainsKey(Message.GetData.Get("d"))) Then Starter.dentroDeGeocerca.Put(Message.GetData.Get("d"), c.GetString("nombre")) nuevoEnGoecerca = True End If ' Log(nuevoEnGoecerca) ' notiBigText("Dentro de Geocerca", $"${Message.GetData.Get("d")} esta dentro de ${c.GetString("nombre")}"$, 777, "Main") End If Next End If If Not(enGoecerca) Then Starter.dentroDeGeocerca.Remove(Message.GetData.Get("d")) ' Log(Starter.dentroDeGeocerca) End If Private textoNoti As String = "" For Each key As String In Starter.dentroDeGeocerca.Keys ' Log(Starter.dentroDeGeocerca.Get(key)) textoNoti = $"${textoNoti}${CRLF}${key} - ${Starter.dentroDeGeocerca.Get(key)} "$ Next If nuevoEnGoecerca Then notiBigText("Geocercas", $"${textoNoti}"$, 777, "Main") ' LogColor("****** " & Starter.dentroDeGeocerca, Colors.blue) ' Subs.notiHigh("Dentro de Geocerca", $"${Message.GetData.Get("d")} esta dentro de ${c.GetString("nombre")}"$, 777, "Main") End If CallSub2(Main, "ubicacionRecibida", Message.GetData) End If 'Si el mensaje es de ruta gps recibida If Message.GetData.ContainsKey("t") And Message.GetData.Get("t") = "ruta" Then Log("Recibimos Ruta GPS") If Message.GetData.ContainsKey("r") Then Log("Tenemos Ruta") Main.base64=Message.GetData.Get("r") descomprimeRuta ' ToastMessageShow("Ruta Recibida: "&Message.GetData.Get("d"),False) Main.rRuta = Message.GetData.Get("d") CallSub(Main, "muestraRuta") End If End If CallSub(Main,"agregaAListview") End Sub Sub Service_Destroy End Sub Sub notiBigText(title2 As String, body2 As String, id2 As String, act As Object) Dim smiley As Bitmap = LoadBitmapResize(File.DirAssets, "logo_keymon.png", 24dip, 24dip, False) Dim n As NB6 n.Initialize("default", Application.LabelName, "HIGH").SmallIcon(smiley) ' Dim cs As CSBuilder n.BigTextStyle("Geocercas", "", "") n.OnGoing(True) ' n.SetDefaults(true, True, True) n.Build(title2, body2, "tag", act).Notify(id2) End Sub Sub descomprimeRuta Dim su As StringUtils Dim decompressedbytes() As Byte = su.DecodeBase64(Main.base64) Log($"decompressedbytesLength: ${decompressedbytes.Length}"$) Dim bc As ByteConverter Main.rutaGPS = bc.StringFromBytes(decompressedbytes,"UTF8") Log($"uncompressedLength: ${Main.rutaGPS.Length}"$) ' Log($"Decompressed String = ${Main.rutaGPS}"$) End Sub