Hallo all, I am converting an existing B4A App receiving and sending firebase notifications. This is due to discontinued Legacy HTTP Protokoll.
With HTTP v1 Api I can send "data style" messages. Recieving messages work with Firebasenotification Receiver as log as app is in foreground.
As soon as app is in background no data are received and log messages from Firebasenotification Receiver are no longer logged. Notifications are displaying "Title" and "Body" instead of received data. B4Ax Pages Main Page continues logging counter when in background.
Logfile message when in background: Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
As soon as app is in foreground messages arrive correct and notifications display data again.
Erels Push Example shows same behavior: Messages including data when App is in foreground, no messages when App is in Background.
Tested App on Xiaomi Poco X3, Android 11 and Huawei P20, Android 9
B4A Version 12.80, Firebasenotifications Library Version 3.1
What am I doin wrong? Any ideas?
With HTTP v1 Api I can send "data style" messages. Recieving messages work with Firebasenotification Receiver as log as app is in foreground.
As soon as app is in background no data are received and log messages from Firebasenotification Receiver are no longer logged. Notifications are displaying "Title" and "Body" instead of received data. B4Ax Pages Main Page continues logging counter when in background.
From FirebaseMessaging Receiver:
Sub Process_Globals
Private fm As FirebaseMessaging
Dim BodyStr As String
Dim myInt As Int
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)
If FirstTime Then
fm.Initialize("fm")
End If
fm.HandleIntent(StartingIntent)
End Sub
public Sub UnSubscribeFromTopics
'fm.UnsubscribeFromTopic(ServGpsSms.FirebaseTopicName)
fm.UnsubscribeFromTopic(B4XPages.MainPage.FirebaseTopicName)
End Sub
Public Sub SubscribeToTopics
Log("FBM Subscribe to Topic: Topicname "& B4XPages.MainPage.FirebaseTopicName)
fm.SubscribeToTopic(B4XPages.MainPage.FirebaseTopicName ) 'you can subscribe to more topics
End Sub
Sub fm_MessageArrived (Message As RemoteMessage)
myInt= myInt +1
Log(DateTime.Time( DateTime.Now) &"------"& myInt &" -------->FBM Message arrived Title:"& Message.GetData.Get("dattitle"))
'Log($"FBM Message data: ${Message.GetData}"$)
If Message.GetData.Get("dattitle") = "ToDucato" Then
BodyStr = Message.GetData.Get("datbody")
Log("FBM BodyToDucato:"&BodyStr)
CallSubDelayed2(B4XPages.MainPage,"ParseFirebaseMessage",BodyStr)
End If
CallSubDelayed2(B4XPages.MainPage,"ParseFBMTest",BodyStr)
Dim n2 As Notification
n2.Initialize2(n2.IMPORTANCE_HIGH)
n2.Icon = "icon"
n2.SetInfo(Message.GetData.Get("dattitle"),myInt, Main)
n2.Notify(1)
End Sub
Logfile message when in background: Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
Extract fromLogmessages:
18:37:07:182 SGPSSMS -----------FBAccesstoken: ya29.a0AfB...
SGPSSMS T4Änderungsstring gesendet: 188;Fahrer...
Application backgrounded at: timestamp_millis: 1707241025203
18:37:07:492 SGPSSMS Job Success: Job.Getstring:
18:37:07:493SGPSSMS JobDone: ++++++++++++++++
Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
18:37:08:186 Timer1 counter :15194
18:37:09:207 Timer1 counter :15195
18:37:10:210 Timer1 counter :15196
18:37:11:216 Timer1 counter :15197
SGPSSMS Bluetoothzähler: 0
SGPSSMS TTTTTTTT VorAbfragesenden: Topic Duc...
SGPSSMS NachAbfragesenden
18:37:12:186 SGPSSMS xxxxxxxxxxJson String: {"message":{"topic":"Duc...
18:37:12:188 SGPSSMS -----------FBAccesstoken: ya29.a0AfB...
SGPSSMS T4Änderungsstring gesendet: 188;Fahrer...
18:37:12:234 Timer1 counter :15198
18:37:12:556 SGPSSMS Job Success: Job.Getstring:
18:37:12:557SGPSSMS JobDone: ++++++++++++++++
Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
18:37:13:254 Timer1 counter :15199
18:37:14:264 Timer1 counter :15200
18:37:15:273 Timer1 counter :15201
18:37:16:286 Timer1 counter :15202
SGPSSMS TTTTTTTT VorAbfragesenden: Topic Duc...
SGPSSMS NachAbfragesenden
18:37:17:196 SGPSSMS xxxxxxxxxxJson String: {"message":{"topic":"Duc..
18:37:17:198 SGPSSMS -----------FBAccesstoken: ya29.a0AfB...
SGPSSMS T4Änderungsstring gesendet: 188;Fahrer...
18:37:17:307 Timer1 counter :15203
18:37:17:596 SGPSSMS Job Success: Job.Getstring:
18:37:17:597SGPSSMS JobDone: ++++++++++++++++
Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
18:37:18:324 Timer1 counter :15204
18:37:19:345 Timer1 counter :15205
Starter Timer6 Aufruf
18:37:20:360 Timer1 counter :15206
18:37:21:381 Timer1 counter :15207
SGPSSMS Bluetoothzähler: 0
SGPSSMS TTTTTTTT VorAbfragesenden: Topic Duc...
SGPSSMS NachAbfragesenden
18:37:22:196 SGPSSMS xxxxxxxxxxJson String: {"message":{"topic":"Duc...
18:37:22:198 SGPSSMS -----------FBAccesstoken: ya29.a0AfB...
SGPSSMS T4Änderungsstring gesendet: 188;Fahrer...
18:37:22:400 Timer1 counter :15208
Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
18:37:22:558 SGPSSMS Job Success: Job.Getstring:
18:37:22:558SGPSSMS JobDone: ++++++++++++++++
18:37:23:408 Timer1 counter :15209
18:37:24:422 Timer1 counter :15210
As soon as app is in foreground messages arrive correct and notifications display data again.
Sub Sendmessage:
Public Sub SendMessage(Topic As String, Title As String, Body As String)
Log("SGPSSMS TTTTTTTT VorAbfragesenden: Topic "& Topic & " :" & FirebaseSenden & " : " & SendFirebaseMessages & " : " & FBAccessToken )
If FirebaseSenden And SendFirebaseMessages Then
Log(" SGPSSMS NachAbfragesenden")
Dim Job As HttpJob
Job.Initialize("fcm", Me)
Dim data3 As Map = CreateMap("priority": "high")
Dim data2 As Map = CreateMap("dattitle": Title, "datbody": Body)
Dim data1 As Map = CreateMap("title": "Title", "body": "Body")
Dim data0 As Map = CreateMap("topic": Topic,"notification":data1,"data":data2,"android":data3)
'generate JSON
Dim data As Map
data.Initialize
data.Put("message",data0)
Dim JG As JSONGenerator
JG.Initialize(data)
Log(DateTime.Time( DateTime.Now) &" SGPSSMS xxxxxxxxxxJson String: " & JG.ToString)
Job.PostString("https://fcm.googleapis.com/v1/projects/gps2smsv1/messages:send", JG.ToString)
Job.GetRequest.SetContentType("application/json;charset=UTF-8")
Job.GetRequest.SetHeader("Authorization", "Bearer " & FBAccessToken)''' auth=<ID_TOKEN>" https://firebase.google.com/docs/database/rest/auth
Log(DateTime.Time( DateTime.Now) &" SGPSSMS -----------FBAccesstoken: " & FBAccessToken)
End If
End Sub
Jobdone:
Sub JobDone(job As HttpJob)
If job.Success Then
Log(DateTime.Time( DateTime.Now) &" SGPSSMS Job Success: Job.Getstring:") ' &job.GetString)
Log(DateTime.Time( DateTime.Now) &"SGPSSMS JobDone: ++++++++++++++++ ") '"&job)
Else
Log(DateTime.Time( DateTime.Now) &"SGPSSMS JobDone: ---------------------- ")
End If
job.Release
'StopMessageLoop '<-- non ui app only
End Sub
Erels Push Example shows same behavior: Messages including data when App is in foreground, no messages when App is in Background.
Tested App on Xiaomi Poco X3, Android 11 and Huawei P20, Android 9
B4A Version 12.80, Firebasenotifications Library Version 3.1
What am I doin wrong? Any ideas?