Ich benutze Retrofit, für meine App, in der Basis-Schnittstelle, verwende ich eine Basis-URL, wie die Retrofit-Seite schlägt vor, Ich möchte in der Lage sein, die BaseUrl von außerhalb der Schnittstelle, so zu ändern habe eine baseUrl für Tests und eine baseUrl für die Entwicklung, und der Benutzer kann zwischen ihnen wechseln. innerhalb einer Java-Schnittstelle alle Variablen sind endgültig und kann nicht geändert werden, und , da die Schnittstelle kann nicht Variablen von außerhalb der beiliegenden Schnittstelle, Wie ändere ich es in Retrofit?Wie baseURL in Retrofit-Schnittstelle zu ändern?
hier ist meine Retrofit-Schnittstelle:
String baseUrl = "http://1.1.1.1:1000/";
//network calls
@GET("api/v1/alignment/measuring")
Call<AligmentDataPojo> getCallData();
@GET("api/v1/alignment/best-position")
Call<BestPositionPojo> getBestPositionCallData();
@GET("api/v1/data/resetBoxAligment")
Call<AligmentScanPojo> resetBoxAligmentCallData();
@GET("api/v1/alignment/pointer-location")
Call<CurserLocationPojo> curserLocationCallData();
@GET("api/v1/alignment/fineAlignment")
Call<FineAligmentPojo> fineAligmentCallData();
@GET("api/v1/alignment/get-bands")
Call<GetBandsPojo> getAllBandsCallData();
@POST("api/v1/alignment/set-band")
Call<PojoSetBand> postAligmentSetBand(@Body SetBandAligmentModel setBandAligmentModel);
@POST("api/v1/alignment/action/start")
Call<PojoSetBand> postAligmentAction(@Body AligmentActionPayloadModel aligmentActionPayloadModel);
@GET("api/v1/alignment/evaluation-results") //Just for mockuppurposeses we have unreal information that we send and simulate a return call
Call<EvaluationDataPojo> getEvaluationResults();
@POST("api/v1/alignment/start-evaluation") //Just for mockuppurposeses we have unreal information that we send and simulate a return call
Call<PojoSetBand> startEvaluationPost(@Body AligmentActionPayloadModel aligmentActionPayloadModel);
//testings
@POST("api/v1/data/testPost")
Call<TestPostModel> getTestPost(@Body TestPostModel testPostModel);
//factory
class Factory {
private static RetrofitInterface service;
public static RetrofitInterface getInstance() {
if (service == null) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.build();
service = retrofit.create(RetrofitInterface.class);
return service;
} else {
return service;
}
}
}
1/Erstellen Sie einen Kommissionierer für die Basis-URL 2/On eine URL Kommissionierung ... 3/Restart-App, um neu zu instantiate Retrofit P. S. Sie können compile 'com.jakewharton: process-phoenix: 1.0.2' für den Neustart der App verwenden. – toshkinl
Vielleicht ist das verwandt. http://stackoverflow.com/questions/38805689/retrofit-change-baseurl –
http://stackoverflow.com/questions/36960627/android-retrofit-design-patterns/36963162#36963162 Werfen Sie einen Blick darauf und erstellen Sie einen Setter für die Basis-URL – Amir