How can I access my localhost from my Android device?

前端 未结 30 2366
面向向阳花
面向向阳花 2020-11-21 05:53

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, th

30条回答
  •  时光取名叫无心
    2020-11-21 06:45

    It is actually quite simple.

    • Turn on WiFi Hotspot of your Android phone/router and connect your Laptop to your phone
    • Start your server at localhost (I am using WAMP server for Windows)
    • Now open the command prompt and enter
    ipconfig
    

    Once you've done that, you will see something like the following:

    Wireless LAN adapter Wireless Network Connection:
      Connection-specific DNS Suffix  . :
      Link-local IPv6 Address . . . . . : fe80::80bc:e378:19ab:e448%11
      IPv4 Address. . . . . . . . . . . : 192.168.43.76
      Subnet Mask . . . . . . . . . . . : 255.255.255.0
      Default Gateway . . . . . . . . . : 192.168.43.1
    
    • Copy the IPv4 Address (in this case, it is 192.168.43.76)
    • In your mobile browser, simply paste the IPv4 Address

    Note: Please set your network as "Home Network". Setting the network as Home Network means that you are allowing your PC to share stuff with other devices on the same network.

    If you are using Windows 10, this can be done with the following:

    • Open Settings
    • Go to Network & Internet
    • Select WiFi in the left menu
    • Tap on the name of the connected WiFi
    • Set the Network Profile of the network to be Private

    If you are having an issue, it is most likely to do with Windows Firewall.

    • Open Control Panel
    • Go to Windows Defender Firewall
    • Tap on Allow an app or feature through Windows Defender Firewall
    • Check whether the app is enabled for Private networks (there should be a tick)
    • If it is not enabled, tap Change settings and tick the checkbox under Private for the app

提交回复
热议问题