Hi, I need your help again. It is very simple but I do not know my error.
I have a ESP32 that send a notification when somebody press the ring of my house
After that, my B4A app recive the notification with this code (Firebasemessaging):
The problem is that I recive two notification like the attached file.
I only want one notification (the notification that shows the hour). Any idea? What is happening?
I have a ESP32 that send a notification when somebody press the ring of my house
B4X:
Private Sub SendMessage(Topic() As Byte, Title() As Byte, Body() As Byte)
'Dim BC As ByteConverter
HttpJob.Initialize(BC.StringFromBytes(Topic))
Dim buffer(300) As Byte 'must be large enough to hold the message payload
Dim raf As RandomAccessFile
raf.Initialize(buffer, True)
WriteBytes(raf, "{""data"":{""title"":""")
WriteBytes(raf, Title)
WriteBytes(raf, """,""body"":""")
WriteBytes(raf, Body)
WriteBytes(raf, """}")
'end of data
WriteBytes(raf, ",""to"":""\/topics\/")
WriteBytes(raf, Topic)
WriteBytes(raf, """")
WriteBytes(raf, ",""priority"": 10")
If BC.StartsWith(Topic, "ios_") Then
WriteBytes(raf, ",""notification"": {""title"": """)
WriteBytes(raf, Title)
WriteBytes(raf, """,""body"":""")
WriteBytes(raf, Body)
WriteBytes(raf, """, ""sound"": ""default""}")
End If
WriteBytes(raf, "}")
HttpJob.AddHeader("Authorization", JoinBytes(Array("key=".GetBytes, API_KEY)))
HttpJob.AddHeader("Content-Type", "application/json")
Log("stack: ", StackBufferUsage, ", buffer size:", raf.CurrentPosition)
HttpJob.Post("https://fcm.googleapis.com/fcm/send", BC.SubString2(buffer, 0, raf.CurrentPosition))
End Sub
After that, my B4A app recive the notification with this code (Firebasemessaging):
B4X:
#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
Private fm As FirebaseMessaging
End Sub
Sub Service_Create
fm.Initialize("fm")
End Sub
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
If FirstTime Then
fm.Initialize("fm")
End If
fm.HandleIntent(StartingIntent)
End Sub
Public Sub SubscribeToTopics
fm.SubscribeToTopic("general")
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 now As Long
Dim HORA,FECHA As String
DateTime.TimeFormat = "hh:mm"
DateTime.DateFormat = "dd MMM yyyy"
FECHA = DateTime.Date(DateTime.now)
HORA = DateTime.Time(DateTime.Now)
'FUNCIONA
Dim n2 As Notification
n2.Initialize2(n2.IMPORTANCE_DEFAULT)
n2.Icon = "icon"
n2.SetInfo("Llaman al timbre", "A las " & HORA & " del " & FECHA,Main )
n2.Notify(4)
End Sub
Sub fm_TokenRefresh (Token As String)
Log("TokenRefresh: " & Token)
End Sub
The problem is that I recive two notification like the attached file.
I only want one notification (the notification that shows the hour). Any idea? What is happening?