4

I'm working on a chess site and I've implemented a rule checker in PHP and I use that on my main site at http://www.chesslords.net/, but, I'm working on an Android frontend in the meantime. However, after I've added the event and drawing correctly to my project, I would like to use my foo.php from my bar.java, calling the rulechecker to generate slots. Do you know how to do that? Thanks in advance for your answer.

1
  • 1
    Here stackoverflow.com/questions/442496/android-http-connection we can find the answer to this problem too, if we follow the instructions given by Reto Meier, and after that we write this kind of code in a try-catch block: InetAddress server = Inet6Address.getByName("www.chesslords.net"); if(server.isReachable(5000)){ } Socket clientsocket = new Socket(server, 21); So, in the manifest file adding the following row outside the application tag solves the connection problem: <uses-permission android:name="android.permission.INTERNET" /> Commented Jun 28, 2010 at 13:31

4 Answers 4

2

Your PHP backend needs to expose an API to the network. It doesn't have to be a specific API or technology (SOAP, JSON, REST, XML-RPC, etc.) Almost any will work as long as you settle on one technique. Having said that, a REST api with JSON encoded data is particularly well suited for Android mobile applications.

Here's an article on creating a REST API in PHP for your backend: http://www.gen-x-design.com/archives/create-a-rest-api-with-php/

Here's one of this years Google IO talks on consuming REST API's in Android: http://code.google.com/events/io/2010/sessions/developing-RESTful-android-apps.html

Those two links should at least get you started.

I'd suggest starting with implementing the server side of the API on your chess website first, possibly testing it with a simple PHP client application, just some simple test scripts to fire of sample request to your service and then look at the returned results.

After you've got the backend working, implementing your Android front-end client should be fairly straightforward.

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

Comments

1

The PHP backend on the server is just going to be bound to URLs, so you'll just be using HTTP requests to get to it - probably by creating an new URL, calling openConnection(), and then using the input and output streams from that.

1 Comment

Yes, from a given URL we want to build our connection, but, first of all, in our manifest file we must give permission to the internet for the project. Elseway it won't connect, even if the source code of the bar.java is correct.
0

Have a look at java.net.HttpUrlConnection

Comments

0

For this kind of purpose i have recently coded a http client in php scripting which solves your query. It can post the data to the server after that you can save it to the database.

http://webtoocool.wordpress.com/2010/07/30/http-client-pfa/

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.