Connect Android app to server running on localhost

Viewed 2571

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.

2 Answers

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.

Related