I can connect to the xampp localhost database with andoird emulator,but when I try it with the real device,it is not connecting.Is there any way to connect my android device to the localhost xampp database .Thanks in advance.
-
do you have xampp database in your android device? – Metehan Sep 10 '14 at 07:03
-
so how do you try to connect it in code? – Metehan Sep 10 '14 at 07:06
-
i am new at android ,so i will have to have xampp database in the android device? – Snehal Sep 10 '14 at 07:11
4 Answers
Localhost to your machine and localhost to your android device isn't the same. When using localhost it typically references the current device that the code is being executed on.
You can probably get around this by using your machine local IP address (typically 192.168.XXX.XXX not 127.0.0.1) if both the device and machine is connected to the same network.

- 191
- 2
- 12
-
Yeah, works. Same network, on computer open CMD, then type ipconfig enter and type in Your Android device browser the ipv4 adress of computer (from CMD). – Adam Staszak Oct 13 '16 at 20:02
This will worked fine for me
http://10.0.2.2/yourfilepath
.I think you need this.Also you can use JSON for manipulate the data in android application,i used this way in my code.

- 5,466
- 17
- 64
- 129
I had gone through exact same problem and i solved it using ip address instead of localhost or 127.0.0.1.

- 441
- 2
- 14
The localhost refers to the device on which the code is running, in this case the emulator.
If you want to refer to the computer which is running the Android simulator, use the IP address 10.0.2.2 instead. You can read more from here.
this link might be helpful : https://stackoverflow.com/a/5806384/3510202