20

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
J. Hesters
  • 13,117
  • 31
  • 133
  • 249
  • 2
    Which version are you targetting? Which devices do you test with? – Xenolion Apr 12 '18 at 20:19
  • @Xenolion I'm targettingg the newest versions. Android 27. And I was testing with Google Pixel 2 and Galaxy S7. Added these infos to the question. – J. Hesters Apr 13 '18 at 11:12
  • did you find out more about this? I'm facing the exact same problem – swalkner Jun 06 '18 at 14:41
  • @swalkner I'm sorry I respond so late. I didn't pay attention to my inbox as much. No I was not able to solve this issue. What we ended up doing with our company was to just send all the messages as loud notifications. It's a bad solution, but it was better than having to do something like sending the real time data to devices via sockets. – J. Hesters Jun 13 '18 at 10:47
  • @J.Hesters : I suggest that you use double-quot i.e. `"` throughout your generated json or use only one symbol `'` or `"` throughout it instead of a mix of both of them. Because even though it is fine to do this in `python` it might not work properly in other languages. – Akram Sep 02 '18 at 13:45
  • @J.Hesters what have you change to make them all **loud** notifications? Can you post your solution? – sebasira Sep 09 '18 at 16:52

1 Answers1

1

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
David Innocent
  • 606
  • 5
  • 16