Android Question Not queued notification

Isac

Active Member
Licensed User
Longtime User
Hello

If I send more than one message with b4j to b4a in format (Data), is it normal that the notification is not queued but overwritten?



-------> b4j



B4X:
Sub SendMessage(Topic As String, Title As String, Body As String)
-----
------
------
Dim data As Map = CreateMap("title": Title, "body": Body)

m.Put("data":data)


-------> b4a

B4X:
Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ID ${Message.MessageId}, Data ${Message.GetData}"$)
    Log("Message="& Message)
    Dim map As Map :map.Initialize
    map = CreateMap("title1":"","body1":Message.GetData)
    Log("map="&map)
    Dim jgen As JSONGenerator
    jgen.Initialize(map)
    Dim n As NB6
    mano = LoadBitmapResize(File.DirAssets, "mano.png", 24dip, 24dip, False)
    n.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(mano)
    n.Build(Message.GetData.Get("title"), Message.GetData.Get("body"), jgen.ToString, Main).Notify(4)
    
End Sub

 

Isac

Active Member
Licensed User
Longtime User
I tried this way, but the message is always overwritten, I honestly did not understand how to use collapse_key

-----> B4J

B4X:
Private Sub SendMessage(Topic As String, Title As String, Body As String)
    Dim Job As HttpJob
    Job.Initialize("fcm", Me)
    Dim m As Map = CreateMap("to": $"/topics/${Topic}"$)
    Dim data As Map = CreateMap("title": Title, "body": Body,"test": "test")
    Dim ok As String =  ("test")
    m.Put("collapse_key", ok)
    m.Put("data": data)
    
    Dim jg As JSONGenerator
    jg.Initialize(m)
    Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
    Job.GetRequest.SetContentType("application/json")
    Job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)
 
Upvote 0

Isac

Active Member
Licensed User
Longtime User
I tried this way, but it does not work, I did not understand how I should use it.
is it right as I wrote?


B4X:
    Dim m As Map = CreateMap("to": $"/topics/${Topic}"$)
    Dim data As Map = CreateMap("title": Title, "body": Body)
    m.Put("collapse_key", "body" & Rnd(1, 1000000))
    m.Put("collapse_key", "title" & Rnd(1, 1000000))
    m.Put("collapse_key", "data" & Rnd(1, 1000000))
    m.Put("data": data)
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…