i have got a php file in my hosting account url link is --http://www.example.com/hello.php i have got simple line code in the file hello.php. I am trying to get the text "Hello" from the php file when a button is pressed in Android and display it in a textView. Can it be done?If give me some examples.Since i havn't developed any web connection based android apps,i have no idea what is this about.
Doing that should be pretty straight-forward:
URL url = new URL("http://www.android.com/");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
readStream(in);
finally {
urlConnection.disconnect();
}
}
You can return a JSON String or whatever you need in your PHP code.
You can learn more about making HTTP connections in android here and always remember to do it in the background to avoid NetworkOnMainThread exceptions.