Reputation: 1035
Here is the idea:
The user types in a command which it has to be send to an android device.
Then the android device runs the command and returns the result to the php page which displays the result in the page!
I have tried with sockets but with no luck(i wanted to keep a connection alive until the closure of the page).
I know how to run commands in my android device:
Runtime.getRuntime().exec( command,args);
And I also know how to send data to the php server:
HttpPost httppost = new HttpPost("http://192.168.10.21/epl371/index.php?");
etc...
The problem is that I want to send data to the android device first via the text box after pressing the submit button.
Is there a way to do this? Is HttpPost a wrong way to do this?
I have tried so many things like:
URL url = new URL(SERVER_URL);
URLConnection connection = url.openConnection();
etc..
Upvotes: 2
Views: 883
Reputation: 23508
Thanks for the clarification!
Since the server most probably has the more permanent IP address, it might be a good idea to write your android application the following way:
When it starts, it sends (via HttpRequest()
, maybe) it's current IP address. This way server knows where to send commands.
While running, application listens on particular IP port for the commands and sends back the replies, you may find details here.
When stopped, application sends to the server the 'stopped' status, so your server knows your phone is gone.
Your server part, besides your form, might require additional handlers for android start/stop requests (see above) and some logic about where to save IP address between page reloads.
Upvotes: 1