How does GCM work in Android

How does push notification technology work on Android?


How did Google implement the push notification function? Does it work through queries run by a service running in the background or otherwise?



Reply:


From what I heard during an Android developer conference in Israel:

A TCP socket is simply waiting in acceptance mode on a cloud Google server. The TCP connection was initiated from the Google Play application. For this reason, Google Play must be installed on the device for Google Cloud Messaging (GCM) (formerly C2DM (Android Cloud to Device Messaging Service)) to work.

When this TCP client socket receives a message, the message contains information such as the packet name of the application it is to be addressed to, and of course the data itself. This data is parsed and packaged into an intention that is sent and ultimately used by the Application is received.

The TCP socket remains open even if the radio status of the device changes to "idle" mode. Applications don't need to be running to get the intentions.

You can find more information at http://developer.android.com/google/gcm/gcm.html







Android maintains an active connection to Google's servers but doesn't use much power or data because it doesn't send any traffic until a Google Cloud Messaging (GCM) message is sent to an app on your phone. There is only one connection on the phone that is used by all apps: installing a new app that uses GCM doesn't add any additional load.

The first step in GCM is for a third party server (such as an email server) to send a request to Google's GCM server. This server then sends the message to your device over this open connection. The Android system checks the message to determine which app it is for and launches that app. The app must be registered with Android in order to use GCM and must have the appropriate authorization. When the app starts, a notification may be created immediately with the data from the message. GCM messages are very limited in size, so the app may instead make a normal connection to a third-party server for more information (such as downloading the headers of new emails).

The advantage of using push notifications is that apps don't have to run periodically to check for new data. This saves both power and data. The advantage of a centralized mechanism like GCM is that the device only needs an open network connection and the Android GCM system is the only one that needs to keep running, rather than having every app running in the background to maintain its own network connection to its own server.

Taken from: Source See also here.




You can implement push notification on Android even with a long polling TCP connection. However, this would involve maintaining an additional socket => battery discharge. Or you can establish a connection with the Alarm Manager at regular intervals.

Google will likely open an outlet for all C2DM push notifications, which will make the battery more efficient.



As of April 10, 2018, Google rejected GCM. The GCM server and client APIs are deprecated and will be removed as of April 11, 2019. Migrate GCM apps to Firebase Cloud Messaging (FCM), which takes over the reliable and scalable GCM infrastructure as well as many new functions.

https://firebase.google.com/docs/cloud-messaging/


Yes you are right. Google had a service (GTalk service) and this service asked Google servers at certain periods of time.



When you receive push notifications on Android devices, the picture of the sender application and a message appear in the status bar. Exactly when the customer taps on the notification, he lands on the application.


We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By continuing, you consent to our use of cookies and other tracking technologies and affirm you're at least 16 years old or have consent from a parent or guardian.

You can read details in our Cookie policy and Privacy policy.