Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to communicate from php to Android

I am making a location application, where user can parameter some function from the server, so I want the server to begin a communication with the phone of the user. But firstly, I want to open a communication with an android, from the php.

Is there a way to communicate with an android phone from a php server?

I already use the communication from android with HTTP to server with return of JSONObject, but I cant find anything for a php call to android.

I think its exactly like the application which can make your phone ring.

like image 295
Crako Avatar asked Mar 07 '13 08:03

Crako


2 Answers

Check out Google Cloud Messaging for Android.

Google Cloud Messaging for Android (GCM) is a service that allows you to send data from your server to your users' Android-powered device. This could be a lightweight message telling your app there is new data to be fetched from the server (for instance, a movie uploaded by a friend), or it could be a message containing up to 4kb of payload data (so apps like instant messaging can consume the message directly).

like image 86
delor Avatar answered Oct 09 '22 00:10

delor


The GET method

You will need to have the Android client connect to your server and pass your JSON messages. If the client needs to get some data from the server and disconnect, then you can just use a normal HTTP type GET.

The WebSocket method

If however, you decide you need a long running TCP connection passing JSON bidirectionally then you should consider something like WebSockets. I have written an Android WebSocket demo. The Android client by default connects to the websocket.org echo server, but that can be easily changed.

I also found a PHP WebSockets implementation.

The Push Method

Now if your plan is to push messages from the server to the client without the client initiating the connection you will need something like GCM (Google Cloud Messaging). Here is an article covering GCM and PHP.

like image 44
Cameron Lowell Palmer Avatar answered Oct 09 '22 00:10

Cameron Lowell Palmer