I tried to use a Firebase Notifications - it works fine, I was able to push a notification from B4J example but my question is - how to keep a previous notification?
Let say I sent a notification with a title "AAA" and body "BBB". It comes to my app and I can see it.
Later on I pushed another notification with a title "AAA2" and body "BBB2". It comes to my app and I can see it. But how about the previous one? I can't see it in a list. Only the last one?
Let say a customer received 5 notifications overnight. How to show all of them but not just a last one?
Her is a code from FirebaseMessagin Service
FirebaseMessaging:
#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
Private fm As FirebaseMessaging
End Sub
Sub Service_Create
fm.Initialize("fm")
End Sub
Public Sub SubscribeToTopics
fm.SubscribeToTopic("general") 'you can subscribe to more topics
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 n As Notification
n.Initialize
n.Icon = "icon"
n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
n.Notify(1)
End Sub
Sub Service_Destroy
End Sub
Notice the "1" in n.Notify(1). From what I understand, that's the notification ID.
My guess, is that if you use the same ID number for each message, then new messages will overwrite the previous notification contents that uses that same ID.
And I guess if you want a second notification to be displayed along side with the first notification, then use a different ID so they will both display.
Notice the "1" in n.Notify(1). From what I understand, that's the notification ID.
My guess, is that if you use the same ID number for each message, then new messages will overwrite the previous notification contents that uses that same ID.
And I guess if you want a second notification to be displayed along with the first notification, then use a different ID so they both will display.
Sub fm_MessageArrived (Message As RemoteMessage)
Log("Message arrived")
Log($"Message data: ${Message.GetData}"$)
Dim n As Notification
n.Initialize
n.Icon = "icon"
n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
n.Notify(1)
End Sub
If I replace n.Notify(1) with n.Notify(Rnd(1,100)) - problem solved. I can see all notification sent tot he client, not just a last one.
As @JohnC already pointed out the ID used in Notify should be different if you want to get multiple Notifications.
Using RND you may loose one if the ID is already used by a Notification.
I would just use an incementing value.
As @JohnC already pointed out the ID used in Notify should be different if you want to get multiple Notifications.
Using RND you may loose one if the ID is already used by a Notification.
I would just use an incementing value.