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.
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.- 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).
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.