I would like to connect my android mobile app to a local server running on 127.0.0.1 so I can access the data from the API to retrieve customer data. How can I do so ? Error is throwing an error as below com.android.volley.NoConnectionError Failed to connect to 127.0.0.1/5000
.
Asked
Active
Viewed 3,550 times
2

MindBrain
- 7,398
- 11
- 54
- 74
-
1Does this answer your question? [How do you connect localhost in the Android emulator?](https://stackoverflow.com/questions/5528850/how-do-you-connect-localhost-in-the-android-emulator) – Aleksei Potapkin Mar 04 '20 at 22:58
2 Answers
4
You can connect to your machine using the 10.0.2.2 ip.
https://developer.android.com/studio/run/emulator-networking#networkaddresses
10.0.2.2 Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)

jeprubio
- 17,312
- 5
- 45
- 56
0
Android studio's emulator's network is separate from your local machine.
So if you use 127.0.0.1, actually you're pointing to your emulator's loopback interface, not your local machine.
To make Android Studio connect to your local machine you need to set your API's Url to 10.0.2.2
.
Also see: https://developer.android.com/studio/run/emulator-networking for more info.

BlueMeth
- 1
- 2