Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 347
adadad Avatar asked May 30 '11 13:05

adadad


People also ask

How do I connect my http localhost web server to my Android device?

You can access your host machine with the IP address "10.0. 2.2". This has been designed in this way by the Android team. So your webserver can perfectly run at localhost and from your Android app you can access it via "http://10.0.2.2:8080".

How can I access my localhost website from mobile?

On your mobile device's browser (any will work), navigate to http://<Local IP Address>:<port number> . For example, if I was serving on localhost:8080 and my local IP address is 123.45. 67.890, on my mobile device's browser I would navigate to http://123.45.67.890:8080 . The http:// is important, don't leave it off.

How do I connect to localhost?

To access the server from itself, use http://localhost/ or http://127.0.0.1/ . To access the server from a separate computer on the same network, use http://192.168.X.X where X.X is your server's local IP address. You can find the sever's local IP address (assuming it's Linux) by running hostname -I . 127.0.


2 Answers

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

like image 118
Michał Jarzyna Avatar answered Oct 29 '22 09:10

Michał Jarzyna


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.

like image 31
Zulkifli fasilkom01 Avatar answered Oct 29 '22 08:10

Zulkifli fasilkom01