1

I have wamp server in my windows. Also I have an android program that it should connect to my database and my php files.I created my database in wamp server and I saved my php files in www folder.

Also I have an image in http://127.0.0.1/index/image.jpg folder in the wamp server and also I use http://127.0.0.1/index/image.jpg in source code.But when I run my program in emulator, It can not load the image from wamp server folder.

I am pretty sure my code is correct.What is the solution?

java
  • 149
  • 1
  • 9

3 Answers3

1

To access your localhost server you'll have to use the special 10.0.2.2 ip. You could also use the real ip of your machine on which the emulator is running on.

More at http://developer.android.com/tools/devices/emulator.html#networkaddresses

Jeffrey Godwyll
  • 3,787
  • 3
  • 26
  • 37
1

You are connecting Android emulator to your localhost, you use 10.0.2.2 for connecting to localhost server.

as android emulator is acting as a device it has it own loopback interface which is 127.0.0.1 therefore it is inside android emulator. and it has its own ip address 10.0.2.15. now that mean you need to connect to server running in your development machine from android emulator.

reference https://developer.android.com/studio/run/emulator-commandline.html#networkaddresses

JDL
  • 1,477
  • 21
  • 31
mubeen
  • 813
  • 2
  • 18
  • 39
0

If you trying to connect device to your pc through wi-fi - they should be in the same network, so ping command on device should return a value. Next you need to open port on your PC, just add a rule for your server in your firewall.

Viktor Yakunin
  • 2,927
  • 3
  • 24
  • 39