Here's what I needed to do to get the device to pick up a local service instance on my Windows machine running on localhost.
- Turn on WiFi on my device and connect to the wireless network.
- Run ipconfig at the command prompt.
- Use an IPv4 address to connect to an Ethernet LAN (since I am connected via Ethernet)
- Change base url in android app to use this url
Then my Android application could connect to the local service instance via this IP address, and not 10.0.2.2, which works when you run the application on the emulator. If someone was so addicted, you could extract these URLs and check if the application is running on an emulator or device, and then set the IP address correctly in the code. Hope this helps.
Edit the url for the above output - I created the ApplicationName.java file and declared this variable:
public static String ANDROID_DEVICE_ID = "";
Then set this variable in my initial action:
ApplicationName.ANDROID_DEVICE_ID = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
Then I copy this device id, and in my api class that calls the web service calls, I have the following code:
private String getCategoriesUrl() { // TODO: Remove before production if (AgoraApplication.ANDROID_DEVICE_ID.equals("deviceIdString")) { _categoriesUrl = _deviceIp + _categoriesUrlSuffix; } else { _categoriesUrl = _emulatorIp + _categoriesUrlSuffix; } return _categoriesUrl; }
Therefore, when I debug on a device or emulator, my application automatically uses the appropriate IP address for service calls.
user534042
source share