简体   繁体   中英

Receiving Messages in an Android GCM app, with a HTTP server (not CCS/XMPP)

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM