Android Question Send Messages to Multiple Devices by firebase ?

aboalwaleed

Member
Licensed User
Longtime User
I want to use for loop and send Messages
B4X:
                    Dim Cursor1 As Cursor =     Main.SQL1.ExecQuery("select * from emps where fin = 1")
                    For i = 0 To Cursor1.Rowcount -1
                        Cursor1.Position = i
                        Topic   = Cursor1.Getstring("emp_mobile")
                        Title  = "Title"
                        Body  = "Body" 
                        CallSub( Me,"SendMessage" )
                    Next

It works with me but can you send it once?
 

DonManfred

Expert
Licensed User
Longtime User
You need to be more patient.

Create a global list of tokensyou want to send to.
Get the first (or the first 10 or so) token and build the message and send it.
Remove the tokens used from the global list.
Get the first (or the first 10 or so) token and build the message and send it.
Remove the tokens used from the global list.
[..]
 
Upvote 0

aboalwaleed

Member
Licensed User
Longtime User
Hi Erel
Did you mean that?
B4X:
                    Dim Cursor1 As Cursor =     Main.SQL1.ExecQuery("select * from emps where fin = 1")
                    Dim m As Map
                    Dim data As Map
                    Dim jg As JSONGenerator
                    For i = 0 To Cursor1.Rowcount -1
                        Cursor1.Position = i
                        Topic   = Cursor1.Getstring("emp_mobile")
                        Title  = "Tile"
                        Body  = "Body  "
                  
                                         
                     
                    m = CreateMap("to": $"/topics/${Topic}"$)
                    data = CreateMap("title": Title, "body": Body,"id":idd)
                    m.Put("data", data)
                     
                        jg.Initialize(m)

                    Next
                    Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
                    Job.GetRequest.SetContentType("application/json;charset=UTF-8")
                    Job.GetRequest.SetHeader("Authorization", "key=" & "AAAAuUAGCooxxxxxxxxx")


But it gives me the error : JSON Array expected
 
Upvote 0
Top