Created
March 23, 2011 19:33
-
-
Save paulononaka/883775 to your computer and use it in GitHub Desktop.
A better way to get a system property.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getSystemProp(String key) throws Exception { | |
Class<?> c = Class.forName("android.os.SystemProperties"); | |
Class<?>[] types = new Class[] {String.class}; | |
Method method = c.getMethod("get", types); | |
return (String) method.invoke(null, new Object[] {key}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reflection was used because Runtime.getRuntime().exec("getprop " + key) some times causes lock. Also, framework's SystemProperties class is not published in SDK.