"I need to switch Base URL based on a user's Location and change other UI components".
I tried throughout the Build Config
but I didn't find anything that seems to work.
"I need to switch Base URL based on a user's Location and change other UI components".
I tried throughout the Build Config
but I didn't find anything that seems to work.
First you have to add servers to strings.xml file then you can use this one to get location country name after that in switch case you can change the server
@Override
protected void onResume() {
String country_name = null;
LocationManager lm =
(LocationManager)getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
Geocoder geocoder = new Geocoder(getApplicationContext());
for(String provider: lm.getAllProviders()) {
@SuppressWarnings("ResourceType") Location location = lm.getLastKnownLocation(provider);
if(location!=null) {
try {
List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if(addresses != null && addresses.size() > 0) {
country_name = addresses.get(0).getCountryName();
break;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Toast.makeText(getApplicationContext(), country_name, Toast.LENGTH_LONG).show();
}