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) orifconfig
(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
- on Linux the one-liner
- there's going to be a bunch of IP's
- try all of them (except the forementioned
localhost
and127.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:
- 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.
- 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.
- 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.
- 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
How to Catch Sigsegv (Segmentation Fault) and Get a Stack Trace Under Jni on Android
How to Encrypt File from Sd Card Using Aes in Android
Email Address Validation in Android on Edittext
How to Make Constraintlayout Work with Percentage Values
No Actionbar in Preferenceactivity After Upgrade to Support Library V21
Generate APK File from Aab File (Android App Bundle)
Panic: Broken Avd System Path. Check Your Android_Sdk_Root Value
How to Shrink Code - 65K Method Limit in Dex
Android - Get Children Inside a View
How to Get the Md5 Fingerprint from Java's Keytool, Not Only Sha-1
How to Downgrade My Sdk Version
Add Ripple Effect to My Button with Button Background Color
Can an Android App Connect Directly to an Online MySQL Database
How to Retrieve the Android Sdk Version
Passing Data from One Activity to Another Using Bundle - Not Displaying in Second Activity