Question

I'm looking for the best approach to send data(String) from my server (PHP) to one specific android device. I can check the device if is online/offline on my server(with http-post method). But I don't know how to send data to spesific device without GCM. (I'm not looking for push notification and I'll send message to maximum 100 user.)

Was it helpful?

Solution

Without using GCM, you have several options:

  • app polls server for updates, at a specified interval. It may impact device's battery life and network usage.
  • app opens TCP connection to the server which is then used by server to send updates to app. I'm pretty sure it's not something you want to do in PHP, though.
  • server sends an SMS to the device (assuming it's a phone) and app intercepts it. This would require your server to know the phone number of the recipient and implies using some SMS API (usually paid).
  • app (WebView or web app) uses WebSockets to connect to server
  • use push service different than GCM (i.e. Urban Airship)

From all of those I would look into polling first. It's often considere somewhat a bad practice, but it's not necessarily the case. Have a look at this AT&T blog post for some measurements.

OTHER TIPS

An other solutions is to use an MQTT .

  1. Install MQTT in your server and create your queue.

  2. Write to the queue in PHP with one of the PHP libraries : https://github.com/mqtt/mqtt.github.io/wiki/libraries

  3. In Android receive the message with http://www.eclipse.org/paho/clients/android/

The communication is asynchronous and all work inside your LAN without external public service (like GCM).

I hope this can be helpful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top