Note: I know that similar questions have been asked here several times, but none of the suggested solutions fixed the problem for me (or I might have missed the correct solution).
I have an Android app which is supposed to talk to a REST API, which is also running on my localhost. However, I cannot access the API, neither from device nor from emulator. These are the URLs I have tried:
Interestingly, I can access the API from device's browser, and also from emulator's browser.
Note that my device is connected to the same WiFi as my laptop, and I have internet permission in my app:
<uses-permission android:name="android.permission.INTERNET"/>
I thought this problem might be happening due to the REST library I use (Volley), however I still cannot access the API by using standard classes from java.net. I am getting 404 from 192.168.0.xx, and timeout from 192.168.1.xx and 10.0.2.2.
I have tried other things like turning on USB tethering, using a different port for my API, disabling WiFi and trying over mobile data etc. but none of them fixed my problem.
Any idea what's going wrong here?