How to get value from strings.xml in modified interface?

We are using a modified android client ( http://square.github.io/retrofit/ ) to make network calls to our server, and I cannot figure out how to access the values ​​in a strings.xml

file from the interface class we created to refit.

Here is a small example of our interface code.

//all retrofit imports
public interface APIService {

    String API_KEY = "XXXX"; //Get this value from strings.xml

    @GET("/api/getNames?api_key=" + API_KEY)
    public ArrayList<String> getNames();
}

      

Right now XXXX is hardcoded, but we want to be taken from strings.xml

.

Thank.

+3


source to share


1 answer


You can pass API_KEY as a parameter using

   @GET("/api/getNames")
   public ArrayList<String> getNames(@Query("api_key") String apiKey);

      



Check the URL Manipulation section URL Manipulation - Retrofit

+2


source







All Articles