Android pushnotification example "hello world"

I am new to Android app development and I'm a little learning. I have a difficult mission to send push notifications (cloud messages) from my web server (PHP) to an Android application (just "helloworld"). I did some googling, and few of my doubts were

  • Does Google send a notification using our "device identifier"?
  • Is there any code in our application other than adding any permission to the manifest to receive a notification?
  • Do we have to register the user device identifier in the "local database" in order to send a notification am I?

Please help me. Plus, can someone show me some sample code or documentation to send a simple notification from a PHP server?

Thank you in advance

+42
android push-notification android-c2dm
May 05 '13 at 16:01
source share
4 answers

http://developer.android.com/google/gcm/index.html

I do not have much knowledge about C2DM. Use GCM, it is very easy to implement and configure.

+22
May 05 '13 at 16:16
source share

Gcm overview: You send a request to google server from your Android phone. You get the registration id as a response. Then you will need to send this registration ID to the server, from where you want to send notifications to your mobile. Using this registration identifier, you can send a notification to the device.

Answer:

  • To send a notification, you send data (message) with the device registration ID to https://android.googleapis.com/gcm/send . (use curl in php).
  • To receive notifications and registration, etc., that’s all you need.
  • You will need to save the registration ID on both the device and the server. If you use GCM.jar, the registration identifier is saved in the settings. If you want, you can save it in your local database.
+25
May 7 '13 at 11:56
source share

Update 2016:

GCM is replaced by FCM

Update 2015:

Check out developers.android.com - Google has replaced C2DM with GCM Demo / How

Update 2014:

1) You need to check on the server what HTTP response you get from Google servers. Make sure this is a 200 OK response, so you know that the message was sent. If you receive a different response (302, etc.), the message will not be sent successfully.

2) It is also necessary to verify the correctness of the registration certificate used. If you specify an invalid registration identifier (as the addressee for the message - indicating the application on a specific device), Google servers cannot successfully send it.

3) You also need to verify that your application has successfully registered with Google servers in order to receive push notifications. If registration failed, you will not receive messages.

First answer 2014

Here is a good question you can take a look at: How to add a push notification in my own Android application

Also here is a good blog with a really easy way: http://blog.serverdensity.com/android-push-notifications-tutorial/

+16
May 05 '13 at 16:11
source share

you can follow this guide

http://www.androidbegin.com/tutorial/android-google-cloud-messaging-gcm-tutorial/

it helped me make a push notification; or you can follow this other tutorial

http://www.tutorialeshtml5.com/2013/10/tutorial-simple-de-gcm-traves-de-php.html

but in Spanish, but you can download the code.

+2
Mar 06 '14 at 3:08
source share



All Articles