How Does WhatsApp overcome the GCM Push notifications delay?

When sending your notification you could set the priority-parameter to "high".

From the docs:

By default, messages are sent with normal priority. Normal priority optimizes the client app's battery consumption, and should be used unless immediate delivery is required. For messages with normal priority, the app may receive the message with unspecified delay.

When a message is sent with high priority, it is sent immediately, and the app can wake a sleeping device and open a network connection to your server.

I know this answer comes late, nevertheless if you are still facing this issue (or anyone else) please tell me if it helps.


The big players

Lets focus on WhatsApp from a scale point of view. Their scale is global and one of the largest in terms of the market share. For players like these it becomes necessary to provide a consistent and smooth user experience no matter what the circumstances are. This means that the "small fish developers" like us are left with pre-defined rules by the big fish companies. Sometimes, it is the implementation that is challenging enough that a lot of the small time developers have to do with whatever is available.

I would like to take WhatsApp's Push Notification as an example to illustrate the above.

First of all, we must stop associating Push notification with Google's services(i.e, Google Play Services) exclusively. Would a device without Google Play services won't receive Push notifications? No, of course it can -- try focusing on the core mechanism of a push notification

How do Push Notifications work - Sockets!

Contrary to a protocol like HTTP which assumes a client-server architecture and is a uni-directional protocol(server can't initiate communication by itself), a plain socket enables communication bi-directionally.

You want to implement your own File transfer protocol over socket? You can!

You want to implement your own Chatting protocol over socket? You can!

You want to implement your own Push notifications protocol over socket? You can!

A socket is the canvas of communication over a network. You can pretty much do anything. Personally we have developed a custom request-response protocol in our organization.

Multiple implementations

Don't stick with default GCM/FCM notification messages protocol or implementation. You can deploy a mechanism to maintain a persistent socket connection with the device and can listen to whatever the server wants to push.

  • WhatsApp uses both GCM/FCM as well as their proprietary XMPP server implementation for Push notifications
  • WhatsApp(and several other Apps) rely upon GCM/FCM(as option 1 - the default) as it is present as a system App on lot of devices and therefore holds a special status where it is very less likely to be killed unlike a normal App.
  • For devices that do not have play services, your custom socket connection is relied upon. It may be that FCM is preferred over socket when the former is available but those are upto you to manage.

From WhatsApp's latest build(2.19.203):

enter image description here

Notice that the relevant permission for FCM is present.

Suspected socket implementation: https://android.stackexchange.com/questions/43970/how-is-whatsapp-able-to-receive-messages-when-not-in-use

XMPP based Push Notifications

From, https://www.quora.com/Does-WhatsApp-use-GCM-to-exchange-messages

No, whatsapp doesn't use GCM[NOT entirely true]. It uses a modified version of XMPP called FunXMPP instead. It changes the XML keywords in message frames to save bandwidth as it's users aka mostly mobile network users, doesn't have a good internet connection. The replacements can be found here: mgp25/Chat-API (I am not the author though)

They have even asked for whitelisting of any port(custom) in use by them.

So, WhatsApp does it. Facebook does it. Google does it. A lot of these companies do this. You can do it as well(to an extent) using Ejjaberd, Openfire or some other technology and having a proper client side implementation for the same.

Chinese ROMs

Some chinese ROMs have taken it even further and radically changed the way the memory and processes are managed in Android. As an example, in Oppo if the Application doesn't have Auto Start turned on, it will not let you do anything once your App is killed. No hopes of any experience whatsoever except hoping that the user will open the App again. In these cases, these OEMs have whitelisted WhatsApp, Facebook, Google and other players selectively. So, who suffers?

Us. Period.