gath gath - 8 days ago 6
Android Question

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?

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.

Comments