1

volley is not working when i want to fetch data from a system on my local network. where URL is like http://192.168.x.x/data.php it works well on emulator but not on a real device. it show a time our error. even i tried setting a maximum time our and retry policy. but in vain.

  • Is your device connected to the same local network? – Robby Cornelissen Jul 21 '16 at 06:45
  • USB doesn't provide network to mobile device. try enabling wifi of your device. – Asif Rahaman Jul 21 '16 at 06:54
  • Possible duplicate of [How can I access my localhost from my Android device?](http://stackoverflow.com/questions/4779963/how-can-i-access-my-localhost-from-my-android-device) – Kushan Jul 21 '16 at 07:04
  • 1
    my phone is connected to same local network as my computer and is working fine if use HttpurlConnection method but dosen't work wheni use volley library – Iqbal Ahmad Aug 25 '16 at 14:24

1 Answers1

0

There are two ways to solve this:

a) keep your device connected to the PC which is connected to your local network either using lan or wifi. Keep debugging mode on. Use ipconfig to check your pcs ipv4 address and use that.

forward your server's port on your router and then use the ipv4 address found on your pc's ipconfig command.

c) Best option-> i use this. Forward your pc's server port on your router, Go to your router's DHCP configurations and give your pc mac a preferred DHCP ip to make sure your router always gives that local ip to your pc(global will still be dynamic if you dont have a static ip). Register to a DDNS and use the set ip above and you will be able to access your web service from anywhere in the world. (i use dynudns for the ddns part)

see How can I access my localhost from my Android device? for other ideas

In the first two steps, make sure that the mobile is connected via wifi so that the router can forward it requests. in third, it can be connected to the internet anyway it likes. Also in the first, you will have to change the url everytime your local ip changes.

In second option, the dns will give a tool for auto ip updation :)

Community
  • 1
  • 1
Kushan
  • 5,855
  • 3
  • 31
  • 45
  • make sure after all these steps that your mobile device actually is connected via wifi in first two cases and any kind of data in the third. – Kushan Jul 21 '16 at 06:58
  • also it should be 192.168.x.x:portno/xyz.php – Kushan Jul 21 '16 at 07:04
  • 1
    my i have tried the connection with normal HttpUrlConnction method and it is working fine but this problem occurs when i use volley libray. it throws a timeout exception and actually doesn't reach the server i think – Iqbal Ahmad Aug 25 '16 at 14:28
  • right this happen to me also, but only for marshmallow, this ahappen after upgrading android studion and lib – Iqbal Rizky Feb 16 '17 at 19:01
  • Another option: http://stackoverflow.com/questions/35650343/access-android-localhost-from-outside/42262832#42262832 – statosdotcom Mar 19 '17 at 04:55