我希望把我的谷歌地图调试和发布关键的不同属性文件:我可以使用.properties文件中的值作为Android字符串资源吗?
debug.properties
maps.api.key = 11111
release.properties
maps.api .key = 22222
我怎样才能使用它们作为字符串资源?
我希望把我的谷歌地图调试和发布关键的不同属性文件:我可以使用.properties文件中的值作为Android字符串资源吗?
debug.properties
maps.api.key = 11111
release.properties
maps.api .key = 22222
我怎样才能使用它们作为字符串资源?
你不能,至少不能直接。欢迎您创建自己的Ant任务,这些任务将生成属性文件或其他任何您想要的字符串资源文件。
是的,你可以
下面是使用属性文件在您的项目的解决方案。
1创建Android专案
2编辑该文件夹的资产名为app.properties文件,并在要使用例如,作为
test=success
和保存文件的属性写
3写这个方法在你的活动课
private Properties loadPropties() throws IOException {
String[] fileList = { "app.properties" };
Properties prop = new Properties();
for (int i = fileList.length - 1; i >= 0; i--) {
String file = fileList[i];
try {
InputStream fileStream = getAssets().open(file);
prop.load(fileStream);
fileStream.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "Ignoring missing property file " + file);
}
}
return prop;
}
4随着onCreate方法写这样
32105某些东西添加必要的进口
更加好,如果你声明自己的应用程序类将是从那里 – Javanator
做到这一点装和投的getProperty值每需要int或字符串或其他 – Javanator