3

I have a php script stored in Wamp server, and want that my application execute it to perform some image treatement from server then the server send the result to the Android phone. Is that possible to perform ? And please if so can you give some hints?

Thank you very much.

androniennn
  • 3,117
  • 11
  • 50
  • 107
  • just call the php script url, and it will be executed. – njzk2 Dec 02 '11 at 15:58
  • 1
    @njzk2: And how to run it as you say? Have you some links ? – androniennn Dec 02 '11 at 16:05
  • @Jakub: That could not be question? Why? Okay, i re-ask the question: how to run a php script stored in a server from Android and then retrieve its results? I hope that is clear now :\ – androniennn Dec 02 '11 at 16:06
  • 1
    i don't see where is the problem actually. you have a php script, it is on a server, just call the corrsponding url, and it run the script – njzk2 Dec 02 '11 at 16:08
  • @njzk2: Okay, thanks :), and for retrieving the treated image, can i send it to the phone? – androniennn Dec 02 '11 at 16:09
  • 1
    you cannot initiate the connection from the server, you have to pull it. otherwise, you can consider C2DM or other push mechanism – njzk2 Dec 02 '11 at 16:11
  • @njzk2: well the first part to execute the script is "easy" and the second part(pulling the image) with C2DM, never heard about it. Will see this push mecanism and hopefully will find some JAVA/Android guides :\ – androniennn Dec 02 '11 at 16:15

2 Answers2

8

Simply perform HTTP get request:

String url = "http://your.domain.com/path/to/file.php";
HttpClient client = new DefaultHttpClient();

try {
  client.execute(new HttpGet(url));
} catch(IOException e) {
  //do something here
}
ioseb
  • 16,625
  • 3
  • 33
  • 29
  • Thank you very much. The problem is the php script will "output" an image (that was treated), how to "take" it and display it in the Android phone? Thanks :). – androniennn Dec 02 '11 at 16:08
  • 1
    client.execute return a nice object that represent the result. which contains everything you need (http status, content-length, content it self, ...) – njzk2 Dec 02 '11 at 16:13
  • @njzk2: be patient please: you informed me that i have to use a push mechanism like c2DM to retrieve the data. Here you write that client.execute return the result of executing the script(content it self). Right? C2DM? client.execute? a little bit confused. Thank your for helping. – androniennn Dec 02 '11 at 16:18
  • 1
    there are always various ways of doing things. If your treatement is a long (more than, says, 60 seconds) one, you may consider doing it on the server and notifiying the client later. that is where push mechanisms like C2DM come into play. However, you should probably start with simple HTTP requests, using the code provided by ioseb. See HttpResponse documentation. for how to handle the result. – njzk2 Dec 02 '11 at 16:21
  • @njzk2: a very good answer, that is clearer now ;). So client.execute will return the treated image. Optimisations? We can thing about other technics ;). Thanks :). – androniennn Dec 02 '11 at 16:28
1

There are various ways to do that 1. You can call the script using webrequest.create from your application Or you can use CURL in case of php application 2. You can execute the script using cron job and schedule it to run according to your need

Link 1

Link 2

Community
  • 1
  • 1
Raj Kumar
  • 6,970
  • 5
  • 30
  • 40
  • Here is a good answer. But please if you have some links post them :). Thank you very much. – androniennn Dec 02 '11 at 16:04
  • http://stackoverflow.com/questions/91275/is-webrequest-the-right-c-sharp-tool-for-interacting-with-websites http://stackoverflow.com/questions/728274/php-curl-post-to-login-to-wordpress – Raj Kumar Dec 02 '11 at 16:20
  • what is webrequest.create here? (and what does it have to do with android?) – njzk2 Dec 02 '11 at 16:22