del_champ
del_champ

Reputation: 179

How Android GCM works?

I was wondering how android push framework is able to distinguish data recieved via GCM and forward it to the appropriate android application for which it was intended ?

Can anyone let me know how it is done ?

Upvotes: 7

Views: 5194

Answers (2)

U.Swap
U.Swap

Reputation: 1939

You question : how android push framework is able to distinguish data recieved via GCM and forward it to the appropriate android application.

From your question it looks like you willing to know about data workflow & Client Server architecture that exists in applications which are using the GCM service.

As per google’s documentation “Google Cloud Messaging for Android (GCM) is a service that helps developers send data from servers to their Android applications on Android devices”. GCM is a service provided by Google for developer that helps developer to send data from server to any number of Android devices.

Simplified Application Specific Work-flow:

The push notification can be broadcasted either to the mass audience or a select set of users. Mass audience is targeted when the notification has to be sent about a marketing campaign. A subset of users are targeted when a personalized information has to be sent.

Simplified Application Specific Work-flow

The below steps explains how push notification works on android devices:

  1. First android device sends sender id, application id to GCM server for registration.
    1. Upon successful registration, GCM server issues registration id to android device.
    2. After receiving registration id, device will send registration id to our server.
    3. Our server will store registration id in the database for further use.
    4. Whenever push notification is needed, our server sends a message to GCM server along with device registration id (which is stored earlier in the database).
    5. GCM server will deliver that message to respected mobile device using device registration id.

This can also be understand using following figure enter image description here

An Example Workflow: Sample WorkFlow

So, from above images it easy to understand that whenever the android application is first installed by the user, then it registers itself to GCM server, and obtains unique GCM ID, then it's our Host servers responsibility to keep this newly registered Registration ID of the android user into Database, and then it will be used whenever server side application willing to send the message to that particular android user.

So, let us consider one case; suppose an Server wants to send Some data to Android User, which has already registered it's GCM ID 1234567 when it's first time installed, and as it's in the server's database the server application will fetch it from DB, and simply make a HTTP POST request to the GCM server in JSON format, which will have registered user's GCM ID along with the data to send , in same way the GCM Server has the record of all the Registered GCM/Android Clients, it directly forwards that message to the intended android user, and android app in user's phone will raise and Notification alert, to indicate an push notification has arrived.

Hope This answers an question!

Upvotes: 13

Dnyanesh
Dnyanesh

Reputation: 331

GCM stands for Google Cloud Messaging. Every push notification receive on any Android device is sent by the GCM only.

sender -> GCM -> Android Device

when sender sends an push notification then it goes to GCM. GCM receives that push and forward it to particular Android Device by its Unique device id.

GCM can't deliver Push without Unique Device ID.

while implementing push notification there are two important things, application key and server key ... these are unique Keys.. using these keys GCM identifies the application to whom push notification is related

Upvotes: 0

Related Questions