How Does Google Cloud Messaging Work?

Google Cloud Messaging (GCM) is a fantastic push notification service for Android apps. However, it can be rather confusing to understand the big picture at first, as there are many interconnected parts. Some of these parts are provided by your app, other parts are provided by GCM and then there is a huge 'black box' you need to provide in order to use GCM, known as the '3rd-party Application Server'. AirBop can handle that last component for you.

Registering apps/devices and sending messages using GCM is a multistage process and AirBop can help you get up and running. This article will walk you through those steps, providing a general overview of the AirBop push notification service and the Google Cloud Messaging service.

The Three Components of GCM

As hinted at above, there are three components that must play a role in the GCM messaging process: the mobile device, the 3rd-party Application Server, and the GCM servers. They are defined in the GCM documentation as:

  • Mobile Device: The device that is running an Android application that uses GCM.
  • 3rd-party Application Server: An application server that developers set up as part of implementing GCM in their applications. The 3rd-party application server sends data to an Android application on the device via the GCM servers. AirBop is an example of a ready-to-use, fully-managed 3rd-party Application Server.
  • GCM Servers: The Google servers involved in taking messages from the 3rd-party application server and sending them to the device.

GCMComponents.png.scaled1000.png

Now that we know what the three components are, let's look at how the interact with one another when registering and sending messages.

Step 1

Your application attempts to register with the Google Cloud messaging (GCM) servers.

AirBopStep1.png

This first step happens on the Android device. Assuming that this is the first time your users have launched your app, your app will attempt to register with the Google Cloud Messaging servers.

Step 2

GCM registers your device and generates a registration Id for your application.

AirBopStep2.png

If your app successfully registers with the GCM servers, the GCM servers will generate a registration Id for your app/device combo and send it back. The registration Id is a string value that will uniquely identify your app on that one specific device. If it's helpful you can think of this as being the "address" of the app on the phone that GCM will use to locate your app in the future.

Step 3

Your app sends the registration Id (plus optional additional information) to the AirBop servers.

AirBopStep3.png

If this step is successful, then your app has registered with both GCM and AirBop, and can now receive messages.

Step 4

You compose a message on the AirBop website.

AirBopStep4.png

The message is composed and is ready to be delivered to registered devices. Delivery can occur right away, or can be scheduled to occur at a future time.

Step 5

The AirBop servers send the message to GCM using the registration Id to target the app and device.

AirBopStep5.png

AirBop delivers the message to the GCM servers along with the registration Ids of registered clients.

Step 6

GCM sends the message to the apps and devices that match the registration Id(s).

AirBopStep6.png

If the registration Id is valid, the GCM servers will send the message to the correct app on the correct device.

Step 7

Your app opens the message and handles the data appropriately.

AirBopStep7.png

In the final step the message has been successfully delivered to your app on registered devices, and your app will analyze the message and perform the task needed.

Step 8

The message can be sent to as many devices that have installed your app and registered with the server.

AirBopStep8.png

Of course in a real situation your message will probably be delivered to tens of thousands (if not hundreds of thousands) of devices and not just one or two.