Android: Release and testing mode?

雨燕双飞 提交于 2019-12-11 23:18:19

问题


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:

  1. pre production configuration: where I use an url for testing (exemple String url = staging.domain.net)
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!