36

In Test app, I have implemented FCM for sending notification messages using

https://github.com/firebase/quickstart-android/tree/master/messaging

For testing I sent the message(8:42 PM) from firebase console using the "New Message" under Notification.

Sent at 8:42 PM

But in my emulator, I have received the message at 9:06 PM

received at 9:06 PM

Please let me know if there is anything to do reduce the delay.

Thank you.

karsas
  • 1,231
  • 4
  • 12
  • 24
  • 1
    The date of delivery here indicates that FCM sent the message to your device. Assuming that there is no bottle necks between FCM and your device/emulator you should receive the message on the order of a few seconds. In your case looks like it took almost an hour. If you are able to reproduce this consistently then I'd file a support ticket with Firebase support, giving some some more information about your situation. https://firebase.google.com/support/ – Arthur Thompson Aug 04 '16 at 16:32
  • @ArthurThompson Even i faced this problem, since yesterday i was trying all sort of things to receive notifications in my Emulator, but only by now, (few minutes back) i received all my notifications from yesterday when i tried it with my tablet in both Emu and Tablet, I had network connectivity all the times in my emulator.. – Bikash Aug 12 '16 at 12:28
  • 1
    This looks like it is a network issue, If you are receiving the messages at all then you have done enough and should receive them quickly unless network conditions prevent it. Are you able to receive other notifications in a more reasonable time frame on the same device/emulator? – Arthur Thompson Aug 12 '16 at 14:15
  • 1
    One question: emulator clean boot, or wake up from saved state? If second one, notifications have huge delay, and it seems to be emulator issue. – user1209216 Feb 13 '18 at 07:19

3 Answers3

33

This could be caused by the unrealistic heartbeat intervals in Firebase Cloud Messaging.

FCM works by maintaining an idle socket connection from an Android device to Google’s servers. This is great because it barely consumes battery power (contrary to polling), and it allows the device to be woken up instantly when a message arrives.

To make sure that the connection remains active, Android will send a heartbeat every 28 minutes on mobile connection and every 15 minutes on WiFi. If the heartbeat failed, the connection has been terminated, and FCM will re-establish it and attempt to retrieve any pending push notifications. The higher the heartbeat interval, the less battery consumed and the less times the device has to be woken up from sleep.

However, this comes at a great price: the longer the heartbeat interval, the longer it takes to identify a broken socket connection. Google has not tested these intervals in real-life situations thoroughly enough before deploying FCM. The problem with these intervals is caused by network routers and mobile carriers, who disconnect idle socket connections after a few minutes of inactivity.

More info is available on my blog:

http://eladnava.com/google-cloud-messaging-extremely-unreliable/

As a workaround, please consider Pushy (https://pushy.me), a drop-in replacement for GCM/FCM which greatly improves notification speed & reliability (Full disclosure - I founded Pushy).

Elad Nava
  • 7,746
  • 2
  • 41
  • 61
  • 2
    If this is the case for android, then how apps like WhatsApp do it instantly when the app is not even in the background? – helado Dec 28 '20 at 05:28
  • 2
    @helado Nowadays, WhatsApp most likely uses FCM high-priority messages (sent with `android.priority: high`) to support this scenario, while also simultaneously attempting to send it over their own socket connection if it is open with the device. – Elad Nava Dec 28 '20 at 15:43
7

My best guess is that this has to do with the message priority.

From the docs:

Setting the priority of a message

You have two options for assigning delivery priority to downstream messages on Android: normal and high priority. Delivery of normal and high priority messages works like this:

Normal priority. This is the default priority for data messages. Normal priority messages won't open network connections on a sleeping device, and their delivery may be delayed to conserve the battery. For less time-sensitive messages, such as notifications of new email or other data to sync, choose normal delivery priority.

High priority. This is the default priority for notification messages. FCM attempts to deliver high priority messages immediately, allowing the FCM service to wake a sleeping device when possible and open a network connection to your app server. Apps with instant messaging, chat, or voice call alerts, for example, generally need to open a network connection and make sure FCM delivers the message to the device without delay. Set high priority if the message is time-critical and requires the user's immediate interaction, but beware that setting your messages to high priority contributes more to battery drain compared with normal priority messages.

I am not certain, but I believe that normal priority is used when you send a message to "All Android devices", which it seems you are doing in the question above. It is also possible that it is being sent to a FCM topic, which is optimized for throughput rather than latency

So, setting the priority to high, or sending to one specific device rather than a topic, should reduce the delay you are seeing.

Also; Be aware that push messages are based on best effort. There are no guarantees that the message will be delivered by a given time, or at all.

Automatico
  • 12,420
  • 9
  • 82
  • 110
  • 5
    Today I had the same problem and I can assure that even `High` priority works the same. Today I have sent the FCM at 10:00A.M with priority `High` and I have received it at 3:44P.M. I have tried with `data` tag just in-case and the result is same. The phone was also not idle. I kept checking by warming up the device by using Chrome and other apps for some time every hour to check how much time it takes. – SkrewEverything May 19 '19 at 10:05
  • @SkrewEverything Have you found any solution? – Sujith S Manjavana Jul 25 '22 at 04:54
  • @SujithSManjavana I don’t know as I stopped working on it long ago – SkrewEverything Jul 25 '22 at 05:32
-1

This issue tracker is dedicated to issues related to the Android Quickstart. The gurus working on this project don't have access to any diagnostics to help troubleshoot FCM issues. Please contact support . https://firebase.google.com/support/