mirror of
https://github.com/cheveguerra/FLP_3.0.git
synced 2026-04-17 19:36:19 +00:00
. Commit inicial.
This commit is contained in:
87
B4A/FirebaseMessaging.bas
Normal file
87
B4A/FirebaseMessaging.bas
Normal file
@@ -0,0 +1,87 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Receiver
|
||||
Version=12.8
|
||||
@EndOfDesignText@
|
||||
'///////////////////////////////////////////////////////////////////////////////////////
|
||||
'/// Agregar estas lineas al editor de manifiestos
|
||||
'
|
||||
' CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
|
||||
' CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
|
||||
' CreateResourceFromFile(Macro, FirebaseAnalytics.FirebaseAnalytics)
|
||||
' CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
|
||||
'
|
||||
'/// Agregar modulo de servicio nuevo FirebaseMessaging y copiar este modulo
|
||||
'
|
||||
'/// Bajar el archivo google-services.json de la consola de Firebase (https://console.firebase.google.com/)
|
||||
'/// El nombre de la app en el archivo json tiene que ser el mismo que el nombre del paquete (Proyecto/Conf de Compilacion/Paquete)
|
||||
'
|
||||
'/// En Starter agregar esta linea
|
||||
'
|
||||
' Sub Service_Create
|
||||
' CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
|
||||
' End Sub
|
||||
'
|
||||
'/// En Main en Sub Process_Globals agregar esta linea
|
||||
'
|
||||
' Private const API_KEY As String = "AAAAv__xxxxxxxxxxxxx-xxxxxxxxxxxxxx-xxxxxxxxxxxx"
|
||||
'
|
||||
'/// Esta llave se consigue igualmente en la consola de Firebase, configuracion de proyecto, Cloud Messaging,
|
||||
'/// es la clave de servidor.
|
||||
'///
|
||||
'/// Se necesitan agregar las librerías: FirebaseAnalitics, FirebaseNotifications, JSON y OkHttpUtils
|
||||
'/// ... JSON es necesario si se van a enviar mensajes, si solo se van a recibir, no es necesario.
|
||||
'
|
||||
'///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Sub Process_Globals
|
||||
Private fm As FirebaseMessaging
|
||||
Dim locRequest As String
|
||||
Dim pe As PhoneEvents
|
||||
Dim batt As Int
|
||||
Dim au As String
|
||||
Dim Sprvsr As String = "Sprv-ML"
|
||||
End Sub
|
||||
|
||||
'Called when an intent is received.
|
||||
'Do not assume that anything else, including the starter service, has run before this method.
|
||||
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
|
||||
Subs.revisaBD
|
||||
fm.Initialize("fm") 'Inicializamos FirebaseMessaging
|
||||
Subs.getPhnId
|
||||
pe.Initialize("pe") 'Para obtener la bateria
|
||||
Subs.revisaBD
|
||||
End Sub
|
||||
|
||||
Public Sub SubscribeToTopics
|
||||
fm.SubscribeToTopic("Trckr") 'Global (you can subscribe to more topics)
|
||||
fm.SubscribeToTopic("Trckr") 'Tracker Global
|
||||
If Starter.logger Then Log("Subscrito a tracker global")
|
||||
fm.SubscribeToTopic("Trckr-ML") 'Global (you can subscribe to more topics)
|
||||
If Starter.logger Then Log("Subscrito a Trckr-ML")
|
||||
fm.SubscribeToTopic(Starter.devModel) 'Propio (you can subscribe to more topics)
|
||||
If Starter.logger Then Log("Subscrito a "&Starter.devModel)
|
||||
If Starter.logger Then Log(fm.token)
|
||||
fm.UnsubscribeFromTopic("Sprvsr") 'Unsubscribe from topic
|
||||
' fm.UnsubscribeFromTopic("Trckr") 'Unsubscribe from topic
|
||||
' fm.UnsubscribeFromTopic("Trckr-ML") 'Unsubscribe from topic
|
||||
' fm.UnsubscribeFromTopic(Starter.devModel) 'Unsubscribe from topic
|
||||
End Sub
|
||||
|
||||
Sub fm_MessageArrived (Message As RemoteMessage)
|
||||
Log("Message arrived")
|
||||
Log($"Message data: ${Message.GetData}"$)
|
||||
If B4XPages.IsInitialized And B4XPages.GetManager.IsForeground Then
|
||||
Log("App is in the foreground. In iOS a notification will not appear while the app is in the foreground (unless UserNotificationCenter is used).")
|
||||
End If
|
||||
Dim n2 As Notification
|
||||
n2.Initialize2(n2.IMPORTANCE_HIGH)
|
||||
n2.Icon = "icon"
|
||||
n2.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
|
||||
n2.Notify(1)
|
||||
End Sub
|
||||
|
||||
Sub fm_TokenRefresh (Token As String)
|
||||
Log("TokenRefresh: " & Token)
|
||||
End Sub
|
||||
Reference in New Issue
Block a user