47

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

ramesh
  • 4,008
  • 13
  • 72
  • 117
  • Here is the detailed post with example explains how to implement push notification from scratch, have look http://www.feelzdroid.com/2016/02/android-google-cloud-messaging-push-notifications-gcm-tutorial.html – Naruto Jan 27 '17 at 16:31

4 Answers4

25

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.
Anirudha Agashe
  • 3,510
  • 2
  • 32
  • 47
24

Firebase: https://firebase.google.com/docs/cloud-messaging/

GCM(Deprecated): http://developer.android.com/google/gcm/index.html

I don't have much knowledge about C2DM. Use GCM, it's very easy to implement and configure.

Saurabh
  • 71,488
  • 40
  • 181
  • 244
ravi roshan
  • 525
  • 3
  • 14
17

Update 2016:

GCM is being replaced with FCM

Update 2015:

Have a look at developers.android.com - Google replaced C2DM with GCM Demo Implementation / How To

Update 2014:

1) You need to check on the server what HTTP response you are getting from the Google servers. Make sure it is a 200 OK response, so you know the message was sent. If you get another response (302, etc) then the message is not being sent successfully.

2) You also need to check that the Registration ID you are using is correct. If you provide the wrong Registration ID (as a destination for the message - specifying the app, on a specific device) then the Google servers cannot successfully send it.

3) You also need to check that your app is successfully registering with the Google servers, to receive push notifications. If the registration fails, you will not receive messages.

First Answer 2014

Here is a good question you may should have a look at it: How to add a push notification in my own android app

Also here is a good blog with a really simple how to: http://blog.serverdensity.com/android-push-notifications-tutorial/

Community
  • 1
  • 1
DominikAngerer
  • 6,354
  • 5
  • 33
  • 60
  • limit the amount of push notices in GCM? – Sunil Kumar Sep 12 '14 at 07:06
  • After Google replaced C2DM with GCM, they took off all limits. SOURCE: http://developer.android.com/google/gcm/c2dm.html#history Prior to GCM (when it was still called C2DM): https://developers.google.com/android/c2dm/#limitations) The only limits you run into the GCM documentation is this: http://developer.android.com/google/gcm/adv.html#lifetime – DominikAngerer Sep 12 '14 at 17:30
  • 1
    Could use another update now that GCM is being replaced with FCM. – Nathan Fig Jul 31 '16 at 03:46
  • 1
    added an Update which includes an FAQ link about the replacement – DominikAngerer Oct 16 '16 at 16:21
2

you can follow this tutorial

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

it helped me to do 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 it's in spanish but you can download the code.