/GCM-Notification-Example

An example program that will use Google Cloud Messaging to send a notifications.

Primary LanguageJavaMIT LicenseMIT

GCM-Notification-Example

This is a complete android+PHP program that will help you understand how can you use Google Cloud Messaging to send notifications to a device.

What this Program will do

This program will register the android device to get a device registrationID from GCM servers and then send it to the PHP script(GCMPushMessage.php) which in turn will send a notification back to this device using the sent registrationID.

How to use

  • Follow this tutorial and get the ProjectID and API KEY.
  • Now open the android project and open MainActivity and replace the SENDER_ID there with your ProjectID.
  • Then open GCMPushMessage.php and replace the SERVER_key with your API KEY.
  • Goto Android strings.xml and replace the server_address with the general path of your server. (For e.g http://localhost).

How Does it work

When you will run the program the following operations occur. > ## Operations > Android (gcmTester) PHP(GCMPushMessage.php) GCM Servers > | | Get Device RegistrationID | > |--------------------------------|------------------------------------------->| > | Send RegistrationID to server | | > |------------------------------->| | > | | Send Notification to this registrationID | > | |------------------------------------------->| > | | Send Notification To Device with RegID | > |<-------------------------------|--------------------------------------------| > | | |

Note : The author of GCMPushMessage.php is Matt Grundy. I've slightly modified it to handle trouble situations also as mentioned in the developer docs.