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.
Copyright 2013 Muazzam Ali
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.