Sub Process_Globals
Public fm As FirebaseMessaging
Private SIN_NOTIFICAR ="sin_notificar" As String
Private mytopic As String
Private smiley As Bitmap
Dim SQL1 As SQL
End Sub
Sub Service_Create
mytopic = Starter.mytopic_id
LogColor("topic firebase: "&mytopic,Colors.Magenta)
fm.Initialize("fm")
smiley = LoadBitmapResize(File.DirAssets, "ham04.png", 24dip, 24dip, False)
End Sub
public Sub SubscribeToTopics
mytopic = Starter.mytopic_id
LogColor(" *********** PASE ************** ",Colors.Blue)
Try
fm.SubscribeToTopic(mytopic) 'you can subscribe to more topics
Dim tiempo = DateTime.Now/100 As Long
ExecuteRemoteQuery($"call app_fcm ('${mytopic}', 'SERVICE FirebaseMessaging', '${tiempo}', 'SERVICIO (3) registro en FCM')"$,"fmc")
Catch
End Try
End Sub
public Sub unSubscribeToTopics
mytopic =Starter.mytopic_id
Try
fm.UnsubscribeFromTopic(mytopic) 'you can subscribe to more topics
Catch
End Try
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)
'Log("Message arrived")
'Log($"Message data: ${Message.GetData}"$)
Dim mapa As Map = Message.GetData
'Log(mapa.Get("notificacion"))
mqtt_MessageArrived(mapa.Get("notificacion"))
End Sub
Sub fm_TokenRefresh (Token As String)
LogColor("Token: "&Token,Colors.Red)
End Sub
Sub Service_Destroy
End Sub
Private Sub mqtt_MessageArrived (Payload As String)
' ToastMessageShow("llego mensaje",True)
Dim notificacion As String = Payload
Dim notificacion_arrivo() As String
notificacion_arrivo = Regex.Split(",",notificacion)
'Log(notificacion_arrivo(0))
HighPriority(notificacion_arrivo(4).Trim,notificacion_arrivo(1).Trim,notificacion_arrivo(2),notificacion_arrivo(9),notificacion_arrivo(2))
'HighPriority
ExecuteRemoteQuery($"CALL gts.app_marca_leido('${notificacion_arrivo(0)}','${notificacion_arrivo(1)}','${notificacion_arrivo(5)}','${notificacion_arrivo(2)}')"$,SIN_NOTIFICAR)
End Sub
Sub HighPriority(mensaje As String, device As String, id As Int, id_sonido As Int, hora As String)
Dim n As NB6
'SONIDO 01
Dim profile As String
If id_sonido = 1 Then
Dim FileName As String = "Ringtone1.mp3"
profile = "Alarmas"
n.Initialize(profile, "Alarmas", "HIGH",True).AutoCancel(True).SmallIcon(smiley)
n.Description("Noticaficación de Alarmas MI PANEL")
End If
If id_sonido = 2 Then
Dim FileName As String = "Ringtone2.mp3"
profile = "Eventos"
n.Initialize(profile, profile, "HIGH",True).AutoCancel(True).SmallIcon(smiley)
n.Description("Noticaficación de Eventos MI PANEL")
End If
File.Copy(File.DirAssets,FileName,Starter.provider.SharedFolder, FileName)
Dim fecha As String
DateTime.DateFormat = "dd MMMM"
DateTime.TimeFormat = "HH:mm"
fecha= DateTime.Date((hora*1000))&" "&DateTime.time((hora*1000))
n.SetDefaults(False, True, True)
'set custom sound
n.CustomSound(Starter.Provider.GetFileUri(FileName))
Dim cs As CSBuilder
n.SubText(cs.Initialize.BackgroundColor(Colors.Transparent).Append($"Hora Evento: ${fecha}"$).PopAll)
Dim title As Object = cs.Initialize.Color(Colors.RGB(69,67,65)).Append("Panel: "&CargarPaneles(device)).PopAll
Dim Content As Object = cs.Initialize.Bold.Append($"Evento: ${mensaje}"$ ).PopAll
Dim largeIcon As Bitmap = LoadBitmapResize(File.DirAssets, "Alarm.png", 100dip, 100dip, True)
n.LargeIcon(largeIcon)
n.Color(Colors.Red)
'n.BadgeIconType("SMALL").Number(1)
n.ShowWhen(DateTime.Now)
n.Build(title, Content, device, Eventos_04).Notify(id)
Sleep(1000)
End Sub
Sub ExecuteRemoteQuery(Query As String, JobName As String)
'*********************************
'**********************************
'Starter.LoadData6(Query,JobName)
'*********************************
'**********************************
End Sub
Sub CargarPaneles( deviceID As String) As String
basedatos
Dim cquery As String
Dim Cursor1 As Cursor
cquery=$"SELECT
panel.nombrepanel
FROM
panel
WHERE
panel.deviceID = '${deviceID}' "$
Cursor1 = SQL1.ExecQuery(cquery)
For i = 0 To Cursor1.RowCount - 1
Cursor1.Position = i
Dim nombre = Cursor1.GetString("nombrepanel") As String
Next
Return nombre
End Sub
Sub basedatos
Dim MyPath As String = File.DirRootExternal & "/Cloud_Alarm"
Dim MyFolder As String = "Cloud_Alarm"
Dim DBFileName As String
DBFileName = "alarm.sqlite"
Dim DBFileDir As String
DBFileDir = MyPath
Try
If File.Exists(MyPath, "") = False Then
File.MakeDir(File.DirRootExternal, MyFolder)
End If
If File.Exists(DBFileDir, DBFileName) = False Then
File.Copy(File.DirAssets, DBFileName, DBFileDir, DBFileName)
End If
SQL1.Initialize(DBFileDir,DBFileName,True)
Catch
End Try
End Sub
#if JAVA
import java.util.ArrayList;
import android.content.Context;
import android.app.NotificationManager;
import android.app.NotificationChannel;
import android.os.Build;
import java.util.List;
import android.net.Uri;
import anywheresoftware.b4a.objects.collections.Map;
public List<Object> mGetNotifChannels() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Context context = BA.applicationContext;
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager == null) {
return null;
}
List<NotificationChannel> l = notificationManager.getNotificationChannels();
List<Object> lMap = new ArrayList();
int i;
for(i = 0; i < l.size()-1; ++i){
NotificationChannel channel = l.get(i);
Object o = getMap(channel);
lMap.add(o);
}
return lMap;
}
return null;
}
public Object mGetNotifChannel(String channelId){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Context context = BA.applicationContext;
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager == null) {
return null;
}
NotificationChannel channel = notificationManager.getNotificationChannel(channelId);
if(channel == null){
return null;
}
return getMap(channel);
}
return null;
}
public Object getMap(NotificationChannel channel){
String Id = channel.getId();
int importance = channel.getImportance();
int lightcolor = channel.getLightColor();
Boolean shVibrate = channel.shouldVibrate();
Boolean shShowLight = channel.shouldShowLights();
Boolean canShowBadge = channel.canShowBadge();
Boolean canBypassDnd = channel.canBypassDnd();
Uri sound = channel.getSound();
anywheresoftware.b4a.objects.collections.Map map = new anywheresoftware.b4a.objects.collections.Map();
map.Initialize();
map.Put("Id", Id);
map.Put("Sound", sound);
map.Put("Importance", importance);
map.Put("Lightcolor", lightcolor);
map.Put("Vibrate", shVibrate);
map.Put("ShowLight", shShowLight);
map.Put("ShowBadge", canShowBadge);
map.Put("BypassDnd", canBypassDnd);
return map.getObject();
}
#End If