2

Here is the idea:

enter image description here

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..
1
  • how is your server connected to the android? are they connected directly by USB cable, or on the same network or totally unrelated devices in the separate networks? Commented Apr 21, 2012 at 10:22

1 Answer 1

1

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:

  1. When it starts, it sends (via HttpRequest(), maybe) it's current IP address. This way server knows where to send commands.

  2. While running, application listens on particular IP port for the commands and sends back the replies, you may find details here.

  3. 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.