Connect an Android Device To a Web Service on Local Host

I implemented a web service for an Android application. The web service is running on my local host (192.168.1.2). Using the Android emulator I succeeded to connect to web service. The I tried to connect my Android device using debugging mode to web service but it didn't work. So my question is if it is possible to connect an Android device to this web service that is running on my local host (192.168.1.2) without using a real IP ?


Solution 1:

It's much simpler way supported by google!

  • Connect your phone via usb to computer and enable usb debugging
  • On your computer open Chrome browser and type exactly this address: chrome://inspect/#devices enter image description here
  • Now you can link your computer port to your device port by port forwarding button. On my computer I have service on address localhost:61437 and I just linked it to device's 8081 port. Remeber to check 'Enable port forwarding' checkbox

enter image description here

  • screen from service on my computer ( localhost:61437 ) enter image description here

  • screen from my mobile browser with the same service ( localhost:8081). And that's it. Also you use this service address in your application enter image description here

Solution 2:

Did you already solve your problem? I also got a problem like you. These are the steps that I already done:

  1. unplug lan cable or turn off any other internet connection from your pc.
  2. connect your android mobile to your pc using usb.
  3. turn on usb tethering
  4. back to your pc. check your ip. mine is 192.168.42.37
  5. check your webservice app in your pc. let's say http://192.168.42.37/webserviceapp
  6. back to your android mobile. try this url http://192.168.42.37/webserviceapp

Now you can access your webservice app in your pc from your mobile phone.