Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to my http://localhost web server from Android Emulator

What can I do in the Android emulator to connect it to my localhost web server page at http://localhost or http://127.0.0.1?

I've tried it, but the emulator still takes my request like a Google search for localhost or worse it says that it didn't found the page while my web server is normally running.

like image 932
Fopa Léon Constantin Avatar asked Apr 27 '11 15:04

Fopa Léon Constantin


People also ask

Can I access localhost from Android emulator?

If you're using Android Studio to run the emulator, then localhost of your host computer will be mapped to the IP address, 10.0. 2.2 , inside the emulator. If you're using other programs to run the emulator, then you may need to consult the documentation associated with those programs.

How can I access my localhost website from mobile?

On your mobile device's browser (any will work), navigate to http://<Local IP Address>:<port number> . For example, if I was serving on localhost:8080 and my local IP address is 123.45. 67.890, on my mobile device's browser I would navigate to http://123.45.67.890:8080 . The http:// is important, don't leave it off.

How can I access my Android apps from localhost?

You can access your host machine with the IP address "10.0. 2.2". This has been designed in this way by the Android team. So your webserver can perfectly run at localhost and from your Android app you can access it via "http://10.0.2.2:8080".

How do I access localhost API from my Android to run an Android app against a localhost API?

Case 1: If You Are Using the Emulator So start up your emulator (since it could take a while until it is ready). Start your server at localhost and attach the debugger. Next, change the API endpoints in your Android code to http://10.0.2.2 . This reroutes the requests from your emulator to your computer's localhost.


1 Answers

The localhost refers to the device on which the code is running, in this case the emulator.

If you want to refer to the computer which is running the Android simulator, use the IP address 10.0.2.2 instead.

enter image description here

You can read more from here.

like image 103
Primal Pappachan Avatar answered Sep 27 '22 19:09

Primal Pappachan