Google Cloud Messaging

Tuesday 2 October 2012 0 comments

About GCM


Google Cloud Messaging for Android (GCM) is a service that helps developers send data from servers to their Android applications on Android devices. This could be a lightweight message telling the Android application that there is new data to be fetched from the server (for instance, an update available for the App or ), or it could be a message containing up to 4kb of payload data (so apps like instant messaging can consume the message directly). The GCM service handles all aspects of queueing of messages and delivery to the target Android application running on the target device.

Things to know before proceeding


  • To receive push notification, Android device should be running with Android V 2.2 or Above. 
  • The 3rd party server, which is used to send message is should be Https server.
  • GCM is meant for alerting the user about any happening and not to describe the content. We can send only 4kb of data.
  • Its allows to send a message to 1,000 recipients at a time. 

Way to proceed


I assume that you have the whole responsibility over the Application which needs to send Push Notification using GCM. First you need to create an Application in Google API console.  Sign in with the Google user Id which you are supposed to create the Application. After signing in, in the left top corner you will find a drop down where you will have the option to Create, open, Rename, Delete and Undelete a project. Create a project with the specified name you will be getting the project id ie Sender Id which is going to be used to send messages in the end of the address bar. Below the project name you will find a option named "Services". It will list out the APIs provided by Google. Change the Status of "Google Cloud Messaging for Android" from OFF to ON. Then click the "API Access" option. Generate the API key for Server if not generated already. Copy the "Key for server apps (with IP locking)" value and it will be used to say Google about the Application.  

Find the folder named "Extras" in your Android Sdk installation folder. If that folder is missing, Update you SDK to revision 20. Open you Eclipse Application.Copy the GCM.jar to your project libs folder and add that to your build path. If you have any issue in adding that to your build path, remove the Jar file and add the to your build path from the Android SDK installation folder. Then copy the GCM Client side package from the same and add that to the source(src) folder of you project. 

Create a service to receive the notification



Add the name of the service and receiver in AndroidManifest file.


Also Add the Internet permission and Permission to receive GCM to manifest file.


After setting all these,  make your Android application to do register with Google  by sending the "Sender Id"  . In turn Google will send a device Token which will be a unique key for your Application and Device. You can call the available methods in the package copied to the Project folder. You can import the Class which have the method to register and return the Token back to us.



Give the obtained token to the Server which will be used to send Notifications. Do registration in regular intervals because Google may refresh your Token.


0 comments:

Post a Comment

 

©Copyright 2011 Bleed in Android | TNB