I have an app that will be deployed to multiple customers on different sites. It uses RetroFit to communicate with the server product.
The problem is that each customer will deploy this server product on their own local server, with its own BASE_URL, so the BASE_URL cannot be hardcoded into the app. It needs to be configured per-device when deploying the app on-site, rather than having a build of the app for each customer.
I have created a Settings screen with a field to edit the BASE_URL and store it in SharedPreferences
. My question is this: Is it possible to replace the BASE_URL with this value from SharedPreferences
on each Call
?
Actually, it doesn't have to be SharedPreferences
. I just need to be able to configure the BASE_URL and store it wherever. Even storing a file on the SD card might be sufficient.
Does anyone have any suggestions? Thanks.
UPDATE: Here is my client code:
public class RestClient {
private static RestInterface REST_CLIENT;
private static final String API_BASE_URL = "http://myurl/";
static {
setupRestClient();
}
private RestClient() {
}
public static RestInterface get() {
return REST_CLIENT;
}
private static void setupRestClient() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API_BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
REST_CLIENT = retrofit.create(RestInterface.class);
}
}
Thanks.