1

I tried to run my retrofit library using example to store data into local server and run from emulator then its works fine but when i run from my mobile then give some error. my question is that how do i run this from my mobile and which kind of ip address i use ?

public static final String ROOT_URL = "http://10.0.2.2:8080"; and also giving error from, public static final String ROOT_URL = "http://127.0.0.1:8080";

with emulator it works but not from any mobile, mobile is supportable and its api level is kitkat and more.

  • post your posting code using retrofit – Divyesh Patel Dec 06 '16 at 07:54
  • if you are running in real device try it with "http://your_local_server_machine_ip:8080" – Nas Dec 06 '16 at 08:22
  • after changing my port number i fnd this error: retrofit.RetrofitError.failed to connect to / "my_server_machine_ip" (port 8080) after 15000ms – Anand Sharma Dec 06 '16 at 08:31
  • check this http://stackoverflow.com/a/17603378/1790537 and http://stackoverflow.com/a/36645473/1790537 make sure your device and server machine are connected via usb. – Nas Dec 06 '16 at 08:43
  • i tried with volley also there timeout error comes but used system ip address also tell me how to over come to this problem – Anand Sharma Dec 07 '16 at 11:51

2 Answers2

3

After waste my hours, I find this code

android:usesCleartextTraffic="true"

add this code to your Manifest.xml between application tags.

Yıldırım
  • 757
  • 10
  • 24
0

You use your computer IP address on real device for example your computer has Ip address of 192.168.0.101:8080 use that url in your root url.

it works on emulator because your emulator is running inside the same computer and 127.0.0.1:8080 is your localhost.

please make sure your computer and your device have same Network i.e same wifi router.

Faraz Ahmed
  • 1,245
  • 1
  • 14
  • 24
  • I tried a lot,I used my system ip address,in same network in different different mobile but not working ,is there any problem with firewall or some solution plz share – Anand Sharma Dec 07 '16 at 11:48