Android Question Firebase Notifications List

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi all.

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
 

JohnC

Expert
Licensed User
Longtime User
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.

But I have not tried this myself.
 
Last edited:
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
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.

But I have not tried this myself.
Thanks for a quick replay - maybe we need to use some random ID.

Will try.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I can't see it in a list.
Did you added the infos to a global list/db/kvs/whatever to later be able to get the old ones too?
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Did you added the infos to a global list/db/kvs/whatever to later be able to get the old ones too?
No I didn't. The problem was in this line

FirebaseMessaging:
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.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
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.

If the solution is ok for your; i´m fine with it.
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
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.

If the solution is ok for your; i´m fine with it.
I will do also incementing value. Rnd was faster just for a test the idea.
 
Upvote 0
Top