0

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 ?

M'hamed
  • 2,508
  • 3
  • 24
  • 41

1 Answers1

0

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
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • I opened run configuration -> target -> additional emulator command line options I have add (-prop url="My_url_for_testing") but how to get this value ? – M'hamed Jul 26 '12 at 11:12
  • getprop url from emulator command line should show the value. Use Runtime.exec() in your app. – Diego Torres Milano Jul 26 '12 at 18:30
  • sorry I kind begginer on this so is it Like this ? java.lang.Process p = Runtime.getRuntime().exec("getprop"); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { System.out.println("line); //<-- Parse data here. } input.close(); – M'hamed Jul 27 '12 at 00:04
  • Yes, but you can get just the property you want: Runtime.getRuntime().exec("getprop url"); – Diego Torres Milano Jul 27 '12 at 04:08