Google Cloud Messaging (GCM)


 

Steps to do before:

Registering with Google Cloud Messaging:

  1. Open the Google Cloud Console.
  2. If you haven’t created the API project yet, click CREATE PROJECT. Give the name of the project and click Create.
    Select Project
    Create New Project
  3. Note down the project number. You will use the project number as sender ID in the registration process.
  4. In the sidebar on the left, click APIs and auth. In the displayed list of APIs, turn the Google Cloud Messaging for Android toggle to ON.
    turn the Google Cloud Messaging API
  5. In the sidebar on the left, click APIs and auth and Credentials.Select Credentials
  6. Click CREATE NEW KEY and select Server Key.
    Creating New Server Key
  7. Provide the list of IP address from which the GCM server accepts the request. Left blank if you want to allow any IP. (Its recommended to provide IP address, so that anyone won’t access to it but for this tutorial purpose i left it blank.).
    gcm_demo7
  8. Copy down the Server Key, you will need this later.
    gcm_demo8

 

Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.

Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, RegistrationIntentService.java and add following code :

Step 5 : Open src -> package -> Create new class, MyGcmListenerService.java and add following code :

Step 6 : Open src -> package -> Create new class, ExternalServerUtilities.java and add following code :

Step 7 : Open src -> package -> Create new class, MyInstanceIDListenerService.java and add following code :

Step 8 : Open src -> package -> Create new class, UnRegistrationIntentService.java and add following code :

Step 9 : Open src -> package -> Create new class, QuickstartPreferences.java and add following code :

Step 10 : Open AndroidManifest.xml and add following code :

Step 11 : Open build.gradle(Module: app) and add following code :

Step 10 : Server Side: saveRegId.php :

Step 11 : Server Side: register.php :

Step 12 : Server Side: MySQL Table :

 

ScreenShots:

gcm gcm3

Download_button