Asked  7 Months ago    Answers:  5   Viewed   2.3k times

I'm fairly new to android and PHP programming and I am currently running into a problem printing my echo statement from my php page, which is as simple as:

    echo "Hey there response!";

What I am currently using in my MainActivity is:


    TextView txtView = (TextView) findViewById(;

    new GetData(txtView).execute("");

Where AsyncTask is defined by:

private class GetData extends AsyncTask<String, Void, String>{
    private TextView display;

    GetData(TextView view){
        this.display = view;
        display = (TextView) findViewById(;

    protected String doInBackground(String... message){
        HttpClient httpclient;
        HttpGet request;
        HttpResponse response = null;
        String result = "error0";
            httpclient = new DefaultHttpClient();
            request = new HttpGet("http://localhost/php/wamp.php");
            response = httpclient.execute(request);
        } catch (Exception e){
            result = "error1";

            BufferedReader rd = new BufferedReader(new InputStreamReader(
            String line="";
            while((line = rd.readLine()) != null){
                result = result + line;
        } catch(Exception e){
            result = "error2";
        return result;

    protected void onPostExecute(String result){

The message in the txtView becomes error2, and I have no idea why.

EDIT I was originally using a non-AsyncTask method of reading in input stream but I have switch to AsyncTask due to Networking error. The problem still persists though since I am not getting the corrent echo in my application.



This is probably too late for yanki but for anybody else that comes across this page.

I tried it with yanki's code and got the same error as him "error 2". I noticed then that I hadn't updated the manifest file to allow internet permissions.

 <uses-permission android:name="android.permission.INTERNET" />

I ran it again and it worked perfectly. So using yanki's code and entering the internet permissions in the manifest file the program should work.

Saturday, May 29, 2021
answered 7 Months ago

I see at least two errors on this code:

private static final String REGISTER_REQUEST_URL = "http://localhost/phptesting/Register.php";

Android doesn't like localhost you can read it here.

Best option is to do an ifconfig and get your ip address and instead of localhost put your ip address like

Also your localhost should have a port, right? So make sure you add it just in case in your BASE_URL, so it should look like this

Then the call should work.

Then I see another problem with

mysqli_stmt_bind_param($statement, "siss",$username,$password,$isAdmin);

You are passing 4 values to an insert that requires 3.

I recommend you to go step by step, first make sure your api call is registering something (you can use PostMan or ARC to do it) and then go to Android side.

Wednesday, March 31, 2021
answered 9 Months ago

where exactly do i need to place the php file

You need to place PHP file in server. (You can use localhost i.e., your machine but for devices outside you need to keep it on a webserver which you need to purchase a domain and hosting services.)

where and how i need to create the php file.

You can create a PHP file in you machine itself. Its as simple as creating a text file but with an extension of .php. Using a wamp on windows (LAMP for linux)you can test it. It has a MySQL in it. LAMP and WAMP will have apache server by default.

Soon after you are finished with writing you php code and testing you can transfer the files through FTP into your webserver. Now to configure the MySQL database you can actually use a control panel at the webserver.

You need to use URL for android application to link the PHP files in turn these PHP files interact with MysQL. for a login lets think like you have created a php file as login.php. On your localhost you can refer it to as http://localhost/myapp/login.php If you need to get it on a webserver which you purchase then you URL will have note that myapp is just a folder where you have uploaded your php files.

Now its just a way by which you can actually have a PHP and MySQL for you android application. I think that tutorials have taught you about using php and mysql connections. For Data exchange you need to know about XML or JSON I think tutorials followed had given you an introduction about it.

You even have a plugin for eclipse to work with php. Just get a help over internet on how to install it. This video might help you.

Saturday, May 29, 2021
answered 7 Months ago

Try to delete the proguard directory in your project. So proguard will forget its mapping.

Saturday, June 19, 2021
answered 6 Months ago

Quoting from Francois Beaufort's G+ post on this topic:

If you're wondering how to get the experimental "available for Android" link on the Chrome Web Store for your Chrome App/Extension, you have to know that there is no way to enter this information into your listing at this time.

However, if the item names and developer email addresses match between Play and CWS, there is a good chance your item will get this link treatment the next time the script runs.

Sunday, August 15, 2021
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :