How to connect to localhost from Android Studio emulator

19,290

Solution 1

You're going to need to connect to your computer's IP.

If you're on Windows open CMD and type ipconfig this will give you your local IP.

If you're on Linux or OSX open terminal and use the ifconfig command.

Since the emulator is a full Android device it has its own network and doesn't use the same hosts file that your machine has. Along with its own IP.

Edit: Grammar fix.

Solution 2

I use my local ip for that i.e. 192.168.0.1 and it works. Verify your local IP.

Share:
19,290

Related videos on Youtube

Firanolfind
Author by

Firanolfind

I am the lonely knight

Updated on June 04, 2022

Comments

  • Firanolfind
    Firanolfind almost 2 years

    I am trying to test web application in Android 2.3.3 browser. Connection using http://10.0.2.2 results "web page is unavailable". Nothing found in Android Studio documentation.

    Does anyone run into the same problem? How did you solve it?

    • greenapps
      greenapps about 7 years
      ` 10.0.2.2`. That is perfectly ok if you use an emulator and the webserver is on the same pc as your emulator is running on.
    • Firanolfind
      Firanolfind about 7 years
      No, it is not, I tried. Seems that 10.0.2.2 was acceptable for ADT. Now it is Android Studio, rules changed.
    • greenapps
      greenapps about 7 years
      And 404 means that the connection with the webserver was established. But the requested page was not found. And indeed you are not requesting a page or there is no default page. But 10.0.2.2 does connect!
    • Firanolfind
      Firanolfind about 7 years
      That was my mistake. It wrote just web page is unavailable. I'll fix question, sorry.
  • Firanolfind
    Firanolfind about 7 years
    It is linux and that helped. Thank you!