Android Question Delay in arrival on Android smartphone of fcm notifications sent from pc

amorosik

Expert
Licensed User
I am using fcm notifications from pc to android smartphone to bring an app to the foreground and set it to work
I'm verifying that sending the notification does not always arrive on the phone quickly
Sometimes it can take several minutes before the notification is received and the app reacts
This operation contrasts with the characteristics of the Google notifications that I seem to have read on the institutional website, where exceptional performances are described, such as 95% of notifications arrive within 250 milliseconds from sending
So the question, addressed to those who have used fcm notifications, is: based on your experience, can notifications be sent even several minutes after sending?
Because if this were really the case then I can't use the fcm notifications to start the app but I have to think of an alternative method
 

KMatle

Expert
Licensed User
Longtime User
It depends which parameters are set (e.g. "importance") and what is defined on the phone. On newer devices (Android 8+) you can define a lot of stuff what happens with messages, too.

Can you post the relevant code how you send the messages?
 
Upvote 0

amorosik

Expert
Licensed User
Is a B4J program that send one fcm notification, then exit

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)
    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
    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;charset=UTF-8")
    Job.GetRequest.SetHeader("Authorization", "key=" & Fcm_Server_Key)
End Sub

Sub JobDone(job As HttpJob)
    Log(job)
    If job.Success Then
        Log(job.GetString)
    End If
    job.Release
    ExitApplication '!
End Sub
 
Upvote 0

amorosik

Expert
Licensed User
Many thanks, I'll try this too
Seeing the link you sent I would ask, how exactly does it differ
B4X:
"android": {"priority": "normal"}
from
B4X:
"webpush": {"headers": {"Urgency": "high"}}
???

And how to translate the second into B4A code?
(may be m.Put ("webpush", CreateMap ("headers": CreateMap ("Urgency": "high")))) ? )
 
Upvote 0
Top