Android "hello world" pushnotification example

ramesh picture ramesh · May 5, 2013 · Viewed 172.1k times · Source

I am new to android application development and I am learning little bit. I am in a hard mission for sending push notification ( cloud messaging ) from my web server ( PHP ) to android application ( just a "helloworld" ). I did some "googling" and few of my doubts are

  1. Google is sending notification using our "device id" right ?
  2. Is there any code needed in our application other than adding some permission in out manifest for receiving notification ?
  3. We have to register user's device id to "local database" in order to send notification am I ?

Please help me Plus can any one please show me a code sample or documentation for sending a simple notification from PHP server ?

Thanks in advance

Answer

Anirudha Agashe picture Anirudha Agashe · May 7, 2013

Overview of gcm: You send a request to google server from your android phone. You receive a registration id as a response. You will then have to send this registration id to the server from where you wish to send notifications to the mobile. Using this registration id you can then send notification to the device.

Answer:

  1. To send a notification you send the data(message) with the registration id of the device to https://android.googleapis.com/gcm/send. (use curl in php).
  2. To receive notification and registration etc, thats all you will be requiring.
  3. You will have to store the registration id on the device as well as on server. If you use GCM.jar the registration id is stored in preferences. If you wish you can save it in your local database as well.