Android "hello world" pushnotification example [closed]
Asked Answered
H

4

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

Homesteader answered 5/5, 2013 at 16:1 Comment(1)
Here is the detailed post with example explains how to implement push notification from scratch, have look feelzdroid.com/2016/02/…Overdraw
A
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.

Aquiver answered 5/5, 2013 at 16:16 Comment(1)
Is there any Demo to Implementation?Carnivore
G
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.
Grassi answered 7/5, 2013 at 11:56 Comment(0)
A
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.

Aquiver answered 5/5, 2013 at 16:16 Comment(1)
Is there any Demo to Implementation?Carnivore
C
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/

Chinquapin answered 5/5, 2013 at 16:11 Comment(4)
limit the amount of push notices in GCM?Arbitrate
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#lifetimeChinquapin
Could use another update now that GCM is being replaced with FCM.Goodnatured
added an Update which includes an FAQ link about the replacementChinquapin
H
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.

Hermann answered 6/3, 2014 at 3:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.