gpt4 book ai didi

android - 将 URL 存储在 string.xml 资源文件中?

转载 作者:搜寻专家 更新时间:2023-11-01 08:40:28 25 4
gpt4 key购买 nike

我正在尝试将一些 API URL 放在某个地方,以便应用程序可以在需要时获取它们。例如,它需要获取 Google Calendar API URL 以检索日历、事件等。

将它们硬编码并存储在 string.xml 中是个好主意吗?否则,什么是更好的方法?

谢谢

最佳答案

根据这个thread您可以将 url 存储在 string.xml 中

我个人更喜欢创建一个“契约(Contract)”文件来存储有关 API 的信息。例如

//No need to use "static final" attributes because this is an interface an not a class
public interface APIContract {
String BASE_URL = "";
//...
}

现在您可以在您的代码中使用它

APIContract.BASE_URL

关于android - 将 URL 存储在 string.xml 资源文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33124760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com