How can I access my localhost from my Android device?

How can i access my localhost from my android device?

  • Am able to access my laptop web server using the android emulator, am using 10.0.2.2:portno works well. But when i connect my real android phone, the phone browser cannot connect to the same web server on my laptop. The phone is connected to the laptop using a USB cable. If i run the adb devices command, i can see my phone. What am i missing? Gath

  • Answer:

    USB doesn't provide network to mobile device. If it's connected to your wifi, then hit your laptop address provided by the router. If it's connected to your mobile network, then first find out your router external IP address, then forward some port to that 10.0.2.2:portno and finally you'll be able to see that server from your device.

gath at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

There is however a far better solution. 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".

Akhil Jain

I found a quick solution to this problem. try this link, it should help you guys fix the problem. http://www.mobitechie.com/android-2/how-to-access-localhost-on-android-over-wifi/ I only changed 1 thing, where the tutorial states you change '127.0.0.1' to 'All', change it to the ip address your server is running on instead. after that you should be able to connect to your localhost.

GertV

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.