I've scoured the internet and can't find an example of anyone trying to set up Push Messaging with GCM from an HTTP server. I've read through Google's example at http://developer.android.com/google/gcm/client.html and it looks like the BrodcastReceiver's onReceive() method is triggered when the app calls gcm.send(). So my question is, if I am not calling gcm.send() (since this is an HTTP server I'm working with), how does onReceive() get triggered?
Asked
Active
Viewed 454 times
1
-
You would have a web page on your server. This could either host PHP or JSP pages. The user would use text fields and submit buttons on such a page to send the messages. – NickT Feb 28 '14 at 16:17
-
I posted an answer to a similar question here: http://stackoverflow.com/questions/21902217/android-push-service-implementing-the-gcm-server-side/21913266#21913266 – NickT Feb 28 '14 at 16:33
-
I'm asking about the client-side (Android app-side) of things. Everything on the server should be fine, but I don't understand how the app receives messages because every example I find online is for CCS and not an HTTP server communication. – HGDev Feb 28 '14 at 18:15
-
The client only knows that its receiver has been triggered by a message that came from Google's server. How your server sent the message to the Google server is irrelevant to the client. – NickT Feb 28 '14 at 18:40
1 Answers
1
You can simply ignore the client code in the demo that calls gcm.send()
. The demo demonstrates both the device to cloud and cloud to device messaging. It triggers the communication in the client, which sends a message to the server via GCM CCS, which in turns sends the same message back to the app.
If you don't use the GCM CCS, you remove the gcm.send()
part from the client code. Your server sends a message to GCM by an HTTP request. GCM server delivers the message to your device and the onReceive
method of your broadcast receiver is triggered.

Eran
- 387,369
- 54
- 702
- 768