Android "hello world" pushnotification example

173,016

Solution 1

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.

Solution 2

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.

Solution 3

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/

Solution 4

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.

Share:
173,016

Related videos on Youtube

ramesh
Author by

ramesh

Updated on April 19, 2020

Comments

  • ramesh
    ramesh about 4 years

    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

    • Naruto
      Naruto over 7 years
      Here is the detailed post with example explains how to implement push notification from scratch, have look feelzdroid.com/2016/02/…
  • Pratik Butani
    Pratik Butani over 10 years
    Is there any Demo to Implementation?
  • Sunil Kumar
    Sunil Kumar over 9 years
    limit the amount of push notices in GCM?
  • DominikAngerer
    DominikAngerer over 9 years
    After Google replaced C2DM with GCM, they took off all limits. SOURCE: developer.android.com/google/gcm/c2dm.html#history Prior to GCM (when it was still called C2DM): developers.google.com/android/c2dm/#limitations) The only limits you run into the GCM documentation is this: developer.android.com/google/gcm/adv.html#lifetime
  • Nathan Fig
    Nathan Fig almost 8 years
    Could use another update now that GCM is being replaced with FCM.
  • DominikAngerer
    DominikAngerer over 7 years
    added an Update which includes an FAQ link about the replacement