如何在改造界面中从 strings.xml 获取值?

How to get a value from strings.xml in a retrofit interface?

我们正在使用改进的 android 客户端 (http://square.github.io/retrofit/) 对我们的服务器进行网络调用,我无法弄清楚如何从界面访问 strings.xml 文件中的值 class 我们为改造而创建的。

这是我们界面代码的一个小示例。

//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();
}

现在 XXXX 是硬编码的,但我们希望它取自 strings.xml

谢谢。

您可以使用

将 API_KEY 作为参数传递
   @GET("/api/getNames")
   public ArrayList<String> getNames(@Query("api_key") String apiKey);

检查URL操作部分URL Manipulation - Retrofit