I'm able to access my laptop web server using the Android emulator, I'm using 10.0.2.2:portno
works well.
But when I connect my real Android phone, the phone browser can't 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?
Best Solution
USB doesn't provide network to mobile device.
If both your desktop and phone are connected to the same WiFi (or any other local network), then use your desktop IP address assigned by the router (not
localhost
and not127.0.0.1
).To find out the IP address of your desktop:
ipconfig
(Windows) orifconfig
(Unix)ifconfig | grep "inet " | grep -v 127.0.0.1
will yield only the important stufflocalhost
and127.0.0.1
)If your phone is connected to the mobile network, then things are going to be harder.
Either go hardcore:
<your desktop IP>:<server port number>
Otherwise use something like xip.io or ngrok.
NOTE: The
ifconfig
command has been deprecated and thus missing by default on Debian Linux, starting from Debian stretch. The new and recommended alternative for examining a network configuration on Debian Linux is ip command. For example to use ip command to display a network configuration run the following:The above ip command can be abbreviated to:
If you still prefer to use
ifconfig
as part of your daily sys admin routine, you can easily install it as part of thenet-tools
package.Reference is here