How can I access my localhost from my Android device?

前端 未结 30 2308
面向向阳花
面向向阳花 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:24

    Ngrok is the best solution. If you're developing PHP then I recommend installing Laravel Valet, It has MacOS and Linux versions, then you may use valet share command. If you're developing any frontend tech and need to share a port like 3000 then use ngrok directly ngrok http 3000

    0 讨论(0)
  • 2020-11-21 06:25

    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.

    0 讨论(0)
  • 2020-11-21 06:26

    On Windows PC You may not need to do anything else than finding out your IPv4 Address using "ipconfig" command.

    • Step 1 : Connect your phone to PC using USB cable.
    • Step 2 : Use command 'ipconfig' to find out your IPv4 Address (External IP of the Router) e.g 192.168.1.5 in my case.
    • Step 3: Just access "192.168.1.5:8080" from your phone browser. It works !

    Other Env Details : Windows 7, Google Nexus 4 (4.2.2), Tomcat Server, Grails Application.

    You should also make sure that you have the permission to access internet in AndroidManifest file :

    <uses-permission android:name="android.permission.INTERNET"/>
    
    0 讨论(0)
  • 2020-11-21 06:27

    EASIEST way (this worked flawlessly for me) is to locally host your site at 0.0.0.0:<port_no> and to access it using mobile devices, use <local_ipv4_address>:<port_no>/<path> in browser.

    • To know your local ipv4 address, just type ipconfig in cmd
    • ANY device connected to the SAME network can access this url.
    0 讨论(0)
  • 2020-11-21 06:28

    A solution to connect my mobile device to my wamp server based on my laptop:

    First, wifi is not a router. So to connect my mobile device to my wamp server based on localhost on my laptop, I need a router. I have downloaded and installed a free virtual router: https://virtualrouter.codeplex.com/

    Configuring it is really simple:

    1. right click on virtual router icon in System Tray
    2. click on Configure virtual router
    3. fill a password
    4. if your internet connection is in ethernet, choose Shared connection : Ethernet
    5. Then set wifi on on your laptop and device
    6. On your device connect to the virtual router network name

    Then you can connect to your laptop via your device by launching a browser and fill the IPV4 address of your laptop (to find it on windows, type in cmd : ipconfig, and find ipv4 address)

    You should see your wamp server home page.

    0 讨论(0)
  • 2020-11-21 06:33

    You may have your web server listening on your loopback interface and not on your network interface. Major signs of this are:

    • Hits on 127.0.0.1 and localhost (from localhost or Android emulator) work
    • Hits on 192.168.xxx.xxx do not work, whether from localhost, LAN, or WAN

    I talk more about diagnosing this and fixing this in an answer here.

    0 讨论(0)
提交回复
热议问题