Connect an Android Device to a Web Service on Local Host

How can I access my localhost from my Android device?

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 not 127.0.0.1).

To find out the IP address of your desktop:

  • type into the command line ipconfig (Windows) or ifconfig (Unix)

    • on Linux the one-liner ifconfig | grep "inet " | grep -v 127.0.0.1 will yield only the important stuff
    • there's a bunch of suggestions on how to have a similar output on Windows
  • there's going to be a bunch of IP's
  • try all of them (except the forementioned localhost and 127.0.0.1)

If your phone is connected to the mobile network, then things are going to be harder.

Either go hardcore:

  • first find out your router external IP address (https://www.google.de/search?q=myip)
  • then, on the router, forward some port to <your desktop IP>:<server port number>
  • finally use the external IP address and forwarded port

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:

ip address

The above ip command can be abbreviated to:

ip a

If you still prefer to use ifconfig as part of your daily sys admin routine, you can easily install it as part of the net-tools package.

apt-get install net-tools

Reference is here

How to connect android phone to a web service run on local server?

Can you run the service on your LAN IP instead of as localhost and connect the phone through wifi?

It can also be possible to connect via setting proxy.

How to connect android device to localhost server?

Windows 7 might block port 8080. You could test that your port is open from another pc using

telnet 192.168.0.3 8080

or from android using this code.

If 8080 is blocked, then you may want to open it using these steps:

  1. Open Windows Firewall by clicking the Start button Picture of the Start button, and then clicking Control Panel. In the search box, type firewall, and then click Windows Firewall.
  2. In the left pane, click Advanced settings. Administrator permission required If you're prompted for an administrator password or confirmation, type the password or provide confirmation.
  3. In the Windows Firewall with Advanced Security dialog box, in the left pane, click Inbound Rules, and then, in the right pane, click New Rule.
  4. Follow the instructions in the New Inbound Rule wizard.

Note: You must be sure beforehand that your android device is connected to the same local area network or wifi.

how to access localhost on android device

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.

Access local host website from Android Device

In the menu at the top of the window in Visual Studio, go to Debug, then Attach to Process (alternatively, press Control Alt P on your keyboard). It will ask you which process to attach to. Choose w3wp.exe and press Attach. The debugger will then connect to your site in IIS, and you'll be able to debug when the Android device is connected to the site.

It should be noted that you'll need to provide the IP of the server in the URL on your Android device, not "localhost".



Related Topics



Leave a reply



Submit