How can I access my localhost from my Android devi

2018-12-31 01:45发布

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?

标签: android
30条回答
姐姐魅力值爆表
2楼-- · 2018-12-31 02:01

use connectify and xampp or equivalent, and type ip address on mobile URL bar to access

查看更多
余生请多指教
3楼-- · 2018-12-31 02:02

Run CMD as administrator

and on CMD screen type ipconfig and the screen will appear with text

as this photo enter image description here

and you can access your localhost using this ip you have to be connected to same network as your pc connected to

查看更多
看风景的人
4楼-- · 2018-12-31 02:05

Adding a solution for future developers.

Copy address of your ip address. right click on your network -> network and sharing-> click on the connection you currently have-> details-> then the address beside ipv4 address is your ip address, note this down somewhere

Go to control panel -> system and security -> windows firewall -> advanced settings -> inbound rules -> new rules (follow the steps to add a port e.g 80, its really simple to follow)

put your ip address that you noted down on your phone browser and the port number you created the rule for beside it. e.g 192.168.0.2:80 and wala.

Possible solution if it doesn't connect. right click network->open network and sharing-> look under view your active connections, under the name of your connection at the type of connection and click on it if it is public, and make sure to change it to a home network.

查看更多
千与千寻千般痛.
5楼-- · 2018-12-31 02:06

Try going to this file: C:\wamp\bin\apache\Apache2.2.11\conf\httpd.conf

#   onlineoffline tag - don't remove
    Order Deny,Allow
    Allow from all // change it Deny
    Allow from 127.0.0.1

And change 10.0.2.2 to your IP address.

查看更多
弹指情弦暗扣
6楼-- · 2018-12-31 02:08

I used this process:

  • Install Fiddler on the PC
  • Set up PC and Android device following these excellent instructions
  • Simply go to the browser on the Android device and type in http://ipv4.fiddler to access the localhost

Note that this process requires you to change the WiFi settings on the Android device at the start and end of every session. I found this less painful then rooting my Android device.

查看更多
临风纵饮
7楼-- · 2018-12-31 02:08

First of all make your machine(where server is running)IP address static. Enter this static IP address in the android code. Next go to your wifi router's interface and check the left panel. You will see option such as port forwarding/forwarding. Click on it and forward port 80. Now edit your htttpd.conf file and edit it for

Allow from All

. Restart your server. Everything should work fine now.

Additionally you can reserve the IP address of your machine so that it is always allocated to you. In the left panel of your router's interface, find DHCP -> Address Reservation, click on it. Enter your machine's MAC address and the IP address you have entered in the code. Click on save. This will reserve the given IP address for your machine.

查看更多
登录 后发表回答