hi, I am creating an android app that is supposed to retrieve data from a remote database (Mysql) I'd like to pass the parameter to my php file using url and get the result that I'll display in the apps can someone have an idea of how to proceed? thank you

Recommended Answers

All 2 Replies

Passing the parameter doesn't work or you don't know how? You should be able to just build a URL with ?'s and &'s in Java as you would normally.

URL url = new URL("http://mywebsite/myservice/fetchmesomething.php?parameter1=" + par1 + "&parameter2=" + par2);

Of course it would be better to encode the URL String first.

Depending on what it is your are sending/retrieving I would suggest creating a simple REST API (can be done in both PHP and Java) that will respond with either plain text, HTML, XML or JSON. Your app would send a request to a REST resource/service that corresponds to a certain task (CREATE, READ, UPDATE or DELETE). There are plenty of tutorials of such an API available on the internet.

I would also suggest reading (or at least skimming) the android tutorials regarding connectivity.

If you are not restricted to Java and feel more comfortable with HTML/CSS/JavaScript you could create the app using a platform like cordova, in which case you could handle the requests and responses using Ajax for instance.

Parameters encoded in the URL are called GET variables. These are easily accessible in your PHP code. There are also POST variables that are not in the URL, hence hidden from simple investigation. These are also easily accessible in your PHP code. Go to the php documentation at the php.net web site for more information about these subjects. You should use POST variables for things like passwords or other sensitive information.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.