【发布时间】:2014-03-13 09:43:03
【问题描述】:
我想在 android 应用程序上创建配置文件,我知道 对于 Xcode 我们使用 plist,Dot net 使用 app.config 但对于 android 我 没有创建文件的想法。
谢谢
【问题讨论】:
标签: android app-config configuration-files
我想在 android 应用程序上创建配置文件,我知道 对于 Xcode 我们使用 plist,Dot net 使用 app.config 但对于 android 我 没有创建文件的想法。
谢谢
【问题讨论】:
标签: android app-config configuration-files
使用SharedPreferences 可以实现这位好先生。
【讨论】:
对于 android 应用程序,我找到了创建 app.properties 文件的方法,在 app.properties 创建之后,很容易从 .properties 文件中获取数据。示例如下:
public void CreatePropertiesFile(Context context)
{
Properties prop = new Properties();
String propertiesPath = context.getFilesDir().getPath().toString() + "/app.properties";
try {
FileOutputStream out = new FileOutputStream(propertiesPath);
prop.setProperty("HomeVersion", "0");
prop.setProperty("DatePlaySquare", "0");
prop.setProperty("CustomerID", "0");
prop.setProperty("DeviceToken", "0");
prop.setProperty("CurrentVersionMobile", "0");
prop.setProperty("Domain", "Megazy");
prop.setProperty("DownloadNewVersion","0");
prop.store(out, null);
out.close();
} catch (IOException e) {
System.err.println("Failed to open app.properties file");
e.printStackTrace();
}
Aey.Sakon
【讨论】: