What I would like to do is create a configuration/properties/xml file in an Eclipse project that can specify project settings.
The context is that I have one application meant for 2 users. But they need to have different version and build numbers and some other parameters specific for that user. What I would like is to have two configuration files, and then be able to specify Configuration file 1 or 2. The tricky part is that Version Code/name are specified in the android Manifest.
How is the best way to go about doing this?
Requirements:
So I found a good way to do this. I simply made a "configuration" xml file that has a bunch of resources in it.
ie:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="version_code">6</integer>
<string name="build_version">1.5</string>
<string name="app_LOGO"> "R.drawable.my_logo"</string>
</resources>
then in my manifest I have
android:versionCode="@integer/version_code"
android:versionName="@string/build_version"
and then I made a configuration class.
public class Configuration {
private int LOGO = 0;
public Configuration(Context cont){
String myResourceId = cont.getResources().getString(R.string.app_LOGO);
String[] resourceParts = myResourceId.split("\\.");
String packName = cont.getPackageName();
int logo = cont.getResources().getIdentifier(resourceParts[2], resourceParts[1], packName);
setLogo(logo);
}
/**
* @return the logo
*/
public int getLogo() {
return LOGO;
}
/**
* set the Logo
*/
public void setLogo(int logo) {
LOGO = logo;
}
}
Where I just call the Configuration class with the context of my activity passed into the constructor inside of my activities onCreate Method. Works like a charm.
Hopefully this helps someone
Cheers.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.