[英]How to get a value from strings.xml in a retrofit interface?
We're using retrofit android client ( http://square.github.io/retrofit/ ) for network calls to our server and I cant figure out how to access values in the strings.xml
file from the interface class that we created for retrofit. 我们正在使用改进的android客户端( http://square.github.io/retrofit/ )来对我们的服务器进行网络调用,我无法弄清楚如何从我们为其创建的接口类访问
strings.xml
文件中的值改造。
Here's a small sample 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 it to get taken from strings.xml
. 现在XXXX是硬编码的,但我们希望它从
strings.xml
获取。
Thank you. 谢谢。
You can pass the API_KEY as a parameter using 您可以使用API_KEY作为参数传递
@GET("/api/getNames")
public ArrayList<String> getNames(@Query("api_key") String apiKey);
Check URL manipulation section URL Manipulation - Retrofit 检查URL操作部分URL操作 - 改造
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.