Sending notifications from the FCM console is now working after a friend straightened me out earlier.
Having trouble creating a notification all by myself. Everything looks groovy in the B4J log, but the device never gets the message.
Log:
Having trouble creating a notification all by myself. Everything looks groovy in the B4J log, but the device never gets the message.
B4X:
Sub AppStart (Args() As String)
SendMessage("general", "mis title", "body slam")
StartMessageLoop
End Sub
Private Sub SendMessage(Topic As String, Title As String, Body As String)
Log("Topic: " & Topic)
Log("Title: " & Title)
Log("Body: " & Body)
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)
If Topic.StartsWith("ios_") Then
Dim iosalert As Map = CreateMap("title": Title, "body": Body, "sound": "default")
m.Put("notification", iosalert)
m.Put("priority", 10)
End If
' neither seems to matter
m.Put("android", CreateMap("priority": "high")) ' Erel
''m.Put("android", CreateMap("priority": 10)) ' Marc - what am i thinking?
m.Put("data", data)
Dim jg As JSONGenerator
jg.Initialize(m)
Log("POST: " & jg.ToString)
Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
Job.GetRequest.SetContentType("application/json;charset=UTF-8")
''Log("using API_KEY" & CRLF & API_KEY)
Job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)
End Sub
Sub JobDone(job As HttpJob)
Log("JobDone: " & job.Success)
If job.Success Then
Log(job.GetString)
End If
job.Release
ExitApplication '!
End Sub
Log:
B4X:
Waiting for debugger to connect...
Program started.
Topic: general
Title: mis title
Body: body slam
POST: {"data":{"title":"mis title","body":"body slam"},"android":{"priority":"high"},"to":"\/topics\/general"}
JobDone: true
{"message_id":4806193666824373742}