问题
I'm working on android project and I want to set some variable on running time, how to do it ?
to be more specific I want to have two running configuration:
- pre production configuration: where I use an url for testing (exemple String url = staging.domain.net)
- production configuration: where I use an other url (exemple url = api.domain.net)
I though about using ant but I have no idea how !
Edit 1:
My application accesses remote servers and services, using a test URL, sometime I want to use the production URL and not test url. So is possible to have two running configuration setting ?
回答1:
You can define both URLs in your code and decide which one to use depending on BuildConfig.DEBUG
.
Alternatively, if you don't want to define them in your code you can use a property (setprop prop value
) and then retrieve it in your app (getprop prop
).
If you are using the emulator there's even a -prop option
-prop <name>=<value> set system property on boot
来源:https://stackoverflow.com/questions/11661547/android-release-and-testing-mode