2017-05-24 7 views
0

안드로이드에서 retrofit을 사용하는 것에있어 새로운입니다. 좋은 방법으로 작업하는 요청을 받았지만 URL의 끝점에 공유 환경 설정의 값을 포함하고 싶습니다.Android 개조 기능 추가 엔드 포인트에서 공유 환경 설정 값 추가

public interface Data{ 
    @GET("/myphone/extra/pull/Sharedpreferencevalue") //add shared preference value here 
} 

내가 개조에서이 작업을 수행 할 수 있습니다 아니면 다른 방법으로해야 할 내 엔드 포인트 URL이 가정? 또는 개장 할 때 어떻게 수행 할 수 있습니까?

프로그래밍 방식 엔드 포인트에 가치를 추가하고,이 같은 뭔가를 @Path 주석을 사용할 수 있습니다
+0

체크 쿼리 매개 변수 @ http://square.github.io/retrofit/ – Raghunandan

답변

0

당신은 동적 매개 변수를 추가 할 수 있습니다

@GET("/myphone/extra/pull/{Sharedpreferencevalue}") 
Call<YourResponseClass> getData(@Path("Sharedpreferencevalue") String value); 
0

당신의 개조 서비스 인터페이스를 다음과 같이

@GET("/myphone/extra/pull/{sharedprefValue}") 
Call<EntityName> getPref(@Path("sharedprefValue") String pref); 
0

url을 동적으로 사용하여 다음과 같이 retrofit2합니다. 사용자 인터페이스

@GET 
public Call<ResponseBody> fetchMileage(@Url String url); 

사용이이 방법

OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); 
    Retrofit.Builder builder = new Retrofit.Builder() 
        .baseUrl(ROOT_URL) 
        .addConverterFactory(GsonConverterFactory.create()); 
    Retrofit retrofit = builder.client(httpClient.build()).build(); 
    MyInterface myInterface = retrofit.create(MyInterface.class); 
    Call<ResponseBody> result = myInterface.fetchMileage(endpointUrl); 
    result.enqueue(new Callback<ResponseBody>() { 
     @Override 
     public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) { 
      String output =""; 
      if (response.isSuccessful()) { 
       try { 

        output = response.body().string(); 


       }catch (IOException e) 
       { 
        e.printStackTrace(); 
       } 


      }else{ 
      } 

     } 

     @Override 
     public void onFailure(Call<ResponseBody> call, Throwable throwable) { 
      //Toast.makeText(context,"Error "+throwable.getMessage(),Toast.LENGTH_LONG).show(); 
      throwable.printStackTrace(); 
     } 
    });