0

I have Spring MVC web application which I want to connect with mine android application in order to use the rest services. I am working with my android phone, ALCATEL ONE TOUCH POP D5, but I didn't succeeded to connect it to access the localhost. I tried with finding my ip address with ipconfig and type it in the browser of the phone, but it doesn't show anything. I also, enabled port 80 in Windows Firewall. I tried with usb tethering, also failed.

My laptop and my android device are on the same network, and I use the phone's network with Wi-Fi tethering.

I would like someone to explain me, the whole scenario about connecting the android device to localhost?

I tryed the solutions from various questions, but they don't seem to work for me, or I am skipping something. Here are the solutions I tried: How can I access my localhost through Android phone? Accessing localhost of PC from USB connected Android mobile device

4 Answers 4

2

I generally use the following approach :

1) Run the web server on local ip of computer on network rather than localhost . In python to accomplish this I run ipconfig in terminal and then do python manage.py runserver [ip]:8000 where ip is ip of computer on network from ipconfig.You can find similar thing for your framework.

See this Link for above implementation :-

Serve Django project on local WiFi Network

2) Then when I hit that IP from any device on same network . I could see the web application running . So same goes for android application . You can access it as normal URL in android.

1

USB doesn't provide network to mobile device. If it's connected to your wifi, then hit your laptop address provided by the router. If it's connected to your mobile network, then first find out your router external IP address, then forward some port to that 10.0.2.2:portno and finally you'll be able to see that server from your device.

3
  • I found this answer in some of the links, but that's not clear to me. Can you explain to me, how can I do this " first find out your router external IP address, then forward some port to that 10.0.2.2:portno and finally you'll be able to see that server from your device", specifically?
    – green
    Mar 10, 2016 at 15:38
  • Start your server at localhost (using wamp server for exemple), enter ipconfig command in your command prompt you will get your "IPv4 Address", then just access with your ipv4adresse:8080 for exemple (192.168.0.7:8080) Mar 10, 2016 at 15:48
  • I did this and it worked. I guess it didn't work before because I was working on the mobile network and my computer was connected to that network via wi-fi hotspot on the mobile. Now, I am on a wifi network with router and I don't have a problem to access it. Thanks!
    – green
    Mar 12, 2016 at 12:55
1

I used the local network IP-addresses like 192.168.0.* to communicate with the server from my smartphone. Both devices must be in the network of course

0

This is what i do:

  1. Run the server on the local host but set custom port not 80 (which is internet defualt port)
  2. make sure your Phone and laptop are connected to the same network
  3. Get your computer ip and in your phone go to the specific Wi-fi network configuration (long click on the network) and click the "Modify network config" -> click the "show advanced options" -> and set proxy setting to manual. then in the host and port insert the computer ip and in the port the port in which the server is running.
  4. In your app web client set the ip to to computer ip and port and you should be able to connect with your server when running the app

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.