How to view localhost on an Android device?

I am trying to open localhost on my htc magic. I connected my device using eclipse via usb. browsing http://10.0.2.2 I get "The page is not avialable. I remember it worked a few days ago

but on emulator i can view localhost

any ideas? considers

+52
android android-emulator
Jul 31 '10 at 14:27
source share
13 answers

I use my local ip for this, i.e. 192.168.0.1, and it works.

+31
Aug 01 '10 at 4:15
source share

An easier way to check in the browser is an emulator like 10.0.2.2 instead of localhost.

Link for localhost

Hope this helps! :)

+46
Jul 27 '12 at 17:28
source share

to access localhost on the emulator: 10.0.2.2. However, this may not always work, for example, if you have something other than a web server such as an XMPP server.

assuming you are on the same wireless network ...

  • find your local ip (it should be something 192.168.1.x) - go to the command line and type "ipconfig" to get it. where x is the assigned local ip of the server machine.

  • use your local ip for your Android device to connect to the local host.

it worked for me.

+20
Mar 18 '12 at 15:52
source share

If you want to access the server running on your PC from your Android device via your wireless network, first run the ipconfig command on your PC (use run (Windows logo + R), cmd, ipconfig).

Note the IPv4 address: (it should be 192.168.0.x) for some x. Use this as the serverโ€™s IP address along with the port number, for example. 192.168.0.7:8080, in your code.

Your Android device will access the server through a wireless router.

+12
Oct 01 '12 at 17:55
source share

I also needed to see localhost on my Android device (Samsung S3) when I was developing a Java web application.
By far, the fastest and easiest way is to go to this link and follow the instructions: https://developer.chrome.com/devtools/docs/remote-debugging

* Note. You must use Google Chrome. *
My resume at the link above:

  • Connect the PC with the phone via USB.
  • Turning on the phone "Developer Settings" from the "Settings"
  • Go to: check the url in PC browser
  • Check the "Discover USB Devices" box (port forwarding if you use them in your web application).
  • Copy / paste the local link into the text field in the browser and click "Open."

Piece of cake

+8
May 20 '14 at 7:31
source share

You can get a public URL for your server running on a specific port on localhost.

At my workplace, I could access the local server using the local IP address of my machine in the application, like most other answers. But at home I could not do this for some reason. After trying many answers and spending many hours, I came across https://ngrok.com . This is pretty straight forward. Just download it from the folder:

ngrok portnumber 

(from the command line in windows)

 ./ngrok portnumber 

(from terminal on Linux)

This will give you a public URL for your local server running on this port number on localhost. You can enable and debug your application using this URL.

You can safely set your local web server on the Internet and fully monitor all traffic. You can also share the URL with a peer developer who can work remotely and can debug the interaction of applications and servers.

Hope this someday saves time.

+4
Jan 04 '14 at 7:18
source share

By combining a few of the above answers plus one additional point, I solved the problem for me.

  • As mentioned above, turn off the firewall [add a specific rule that allows incoming connections to the port as soon as you successfully connect)
  • Find the IP address using ipconfig as above.
  • Make sure your web server is bound to the ip address above, not just 127.0.0.1. Check this locally by looking at the ip address and port. For example. 192.168.1.113:8888. If not, find a solution. For example. https://groups.google.com/forum/?fromgroups=#!topic/google-appengine-java/z4rtqkKO2hg
  • Now test it on your Android device. Please note that I also disconnected my data connection and used exclusively Wi-Fi connection on my Android.
+3
Oct. 14 '12 at 3:21
source share

If your local host is not running on the default HTTP port (which is port 80), you need to specify the port in your URL to match the port on which your localhost is running. For example. If your local host is running, say port 85, your URL should be

 http://10.0.2.2:85 
+1
Sep 17 '12 at 9:50
source share

If your firewall is turned on, turn it off and use IPv4 to test your application on the device itself, and then check your application.

0
Oct 07
source share

I had a similar problem, but I could not solve it using a static IP address or changing the firewall settings. I found a useful utility that can be configured in a minute.

We can host our local web server in the cloud for free. By exposing it in the cloud, we get a different URL, which we can use instead of localhost, and access the web server from anywhere.

Ngrok utility https://ngrok.com/download Steps:

  1. Sign up
  2. Download
  3. Extract the file and double click it to start it, the command line will open
  4. Type "ngrok.exe http 80" without quotes on the host, for example, the Apache APAMPP server, which runs on port 80.
  5. Copy the new URL name generated on the cmd command line, for example if it looks like "fafb42f.ngrok.io"

URL: http: //localhost/php/test.php Should be changed as follows: http://fafb42f.ngrok.io/php/test.php

This URL can now be obtained from the phone.

0
Apr 20 '18 at 5:49
source share

Mac OSX Users

If your phone and laptop are on the same Wi-Fi:

Go to System Preferences > Networ k to get your IP address.

In your mobile browser, enter [your IP address]:3000 to access localhost:3000

e.g. 12.45.123.456:3000

0
Aug 21 '18 at 10:42
source share

I am using testproxy for this.

 npm install testproxy testproxy http://10.0.2.2 

You will then receive a URL (and a QR code) that you can receive on your mobile device. It even works with virtual machines that you cannot reach by simply entering the IP address of your development machine.

0
Aug 30 '18 at 20:32
source share

For Mac user:

I worked on this issue for one day until I realized that the Xampp that I used was not a real "Xampp". It was a Xampp virtual machine that runs on a Linux virtual machine. This made it not working on the local host, instead, a different IP. I installed real Xampp and ran my local server on localhost, and then just got access to it from the IP address of my mac.

Hope this helps someone.

0
May 05 '19 at 17:44
source share



All Articles