GCM(1)Get Start
GCM(1)Get Start 1. Getting Started Follow the document to create Google APIs Console project The URL are as follow: https://code.google.com/apis/console/ I click create project to create an API project and then rename it to easymessagepush. Take a note of my project number *** Enabling the GCM Service Click on the Service tab menu and turn on the 'Google Cloud Messaging for Android' Obtaining an API Key Select the tab menu, 'API Access' I just select the 3 one by one Create new Server key Create new Browser key Create new Android key I did not type in something, I want make them allowed for any app, any IP and any referer right now, maybe I will change that in the future. Install the Helper Libraries From the SDK Manager on eclipse, find the menu Extras ---> Google Cloud Messaging for Android Library Install this feature, it will create a GCM directory under my SDK ROOT/extras/google/ For me, that is /opt/android-sdk/extras/google Everything will be in this directory /opt/android-sdk/extras/google/gcm Writing the Android Application Step1: Copy the gcm.jar file into our application classpath find the gcm.jar from here gcm-client/dist My project is managed by MAVEN, so I decide to add this in pom.xml com.google.android gcm 1.0.2 Step2: Make the following changes in the application's Android manifest 1. GCM requires Android 2.2 or later, make sure we have this kind of line in AndroidManifest.xml 2. Declare and use a custom permission so only this application can receive GCM message: The package name com.sillycat.easyrestclientandroid should be the same as 4. Add the following broadcast receiver …snip... …snip… This broadcast receiver is responsible for handling the 2 intents that can be sent by GCM. com.google.android.c2dm.intent.RECEIVE com.google.android.c2dm.intent.REGISTRATION These should be defined in the manifest(rather than programmatically) so that these intents can be received even if the application is not running. 5. Add the following intent service …snip.. …snip... This intent service will be called by the GCMBroadcastReceiver. Step 3: Write the GCMIntentService class The detail of the project is in the sample EasyRestClientAndroid project. Writing the Server-side Application The detail is in project 4mymessage project. References: https://developer.android.com/google/gcm/gcm.html https://developer.android.com/google/gcm/gs.html