TLDR: Messages send to Android devices via FCM take between 10 seconds and 5 minutes to get delivered. Probably due to priority. I set it to "high", but it seems like it doesn't stay on that value.
I develop an app both for iOS and Android. My backend runs on Django. For our realtime communication we recently started using Firebase Cloud Messaging (FCM).
I successfully managed to connect the Django server and am able to send messages to both kind of devices.
Here is my python code that constructs the message. Note that the token data gets appended later dynamically and that the messages are silent notifications.
def _build_silent_message(not_id, data):
"""Construct silent notifiation message.
Silent means that this message won't show up in the notifications hub
of the app.
"""
return {
'message': {
'data': {"data": data},
'apns': {
'payload': {
"notId": not_id, # notId HAS TO BE FIRST!!!
'aps': {
'content-available': 1
}
},
'headers': {
'apns-priority': '10'
},
},
'android': {
'priority': "high",
'data': {
"androidData": data,
'content-available': '1'
}
}
}
}
As you can see I set both the Apple and the Android priority to "high" (/ 10). On iOS all the messages get delivered immediately. On Android however this is not the case. Messages take up to 5 minutes until they arrive on the phones. I think this might be a priority issue, as the documentation states:
High priority. FCM attempts to deliver high priority messages immediately, allowing the FCM service to wake a sleeping device when necessary and to run some limited processing (including very limited network access).
So far so good. I set the priority to high. But the documentation further states:
High priority messages generally should result in user interaction with your app. If FCM detects a pattern in which they don't, your messages may be de-prioritized.
All my messages I sent to the devices do require interaction with the phone. But all my messages are silent messages. Maybe FCM thinks my messages aren't requiring user interaction and therefore gives it a lower priority.
Does any one know how to solve this?
EDIT: I tested with Android Samsung Galaxy S7 and Google Pixel 2.
There are two ways users can receive silent push notifications on Android. Users can long press on a notification to get an option to display notifications silently. Users can also enable silent notifications by heading to Settings > App & Notifications > Search for app and choose> Notifications, and turn it off.
FCM does not guarantee the order of delivery. Some typical use cases of non-collapsible messages are chat messages or critical messages.
Using Firebase Cloud Messaging, we can send three types of messages, i.e., Notification Message, Data Message, and the message with both Notification & Data Payload.
You don't have access to the way FCM delivers the messages to the device. Just because you marked the message as high priority doesn't mean it is a high priority message that should be delivered immediately.
FCM will observe the interactivity of your notifications/FCM messages. If the user doesn't usually follow through with interacting with them FCM will de-prioritize your messages hence a longer delivery time.
FCM is intrusive in regards to UX...FCM was created in a way not to expose the user to irrelevant data. Think of it as an adBlocker that keeps you away from interrupting a user.
Check out the official documentation for FCM on how it works.
https://firebase.google.com/docs/cloud-messaging/concept-options
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With