8

Can I (in the Manifest file or somewhere else) set system properties for my Android application?

I want to use a library that can be configured using system properties, and being able to just use that mechanism would reduce the amount of code I need to write.

Thilo
  • 257,207
  • 101
  • 511
  • 656
  • Android seems to have no equivalent to the [java -D option](https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html#BABDJJFI) for presetting a system property before the code runs, e.g. no manifest directive. Other negative answers about the java option approach: [here](http://stackoverflow.com/questions/16037234) and [here](http://stackoverflow.com/questions/26316622). – Michael Allan Jun 29 '15 at 20:30

1 Answers1

4

Yes, you can set system properties for your app.

String myprop;
System.setProperty("MYPROP", "4");
myprop = System.getProperty("MYPROP");
Log.i(TAG, "MYPROP: " + myprop);

Here, you set and geta system property from the Java "world". To access it from the C/C++ world (NDK), ie your lib, check out this post: Calling a java method from c++ in Android.

Community
  • 1
  • 1
m-ric
  • 5,621
  • 7
  • 38
  • 51
  • 1
    Yes, but that would be in code. I want to reduce the amount of code that I need to write by having it in a file somewhere. (Of course, your suggestions makes it possible for me to write a small helper class that sets properties from a file) – Thilo Aug 17 '12 at 23:19