heading

heading

Monday, 14 October 2013

Accessing Localhost Server from Android Emulator


A common headache that novice developers face while using the Android emulator is, how to access the localhost server  from any Android Virtual Device. 

Do you recognize these address commands?

http://localhost/...
http://127.0.0.1/...

You are right! We use them in browsers to access our localhost files. However, these cannot be used in the case of Android Emulators. I'll keep it short and simple without going into nerdy stuff. You can access the localhost of your machine from the emulator using the address command http://10.0.2.2/. Another method is to use your own IP address, for instance http://192.168.2.224/. However this solution is not appropriate if your IP Address is dynamically allocated. The address will keep changing, therefore I recommend to use the http://10.0.2.2/.

Examples: http://10.0.2.2/Mypage, http://192.168.2.224/index.php, http://10.0.2.2:80/home.php.