Skip to content

Instantly share code, notes, and snippets.

@paulononaka
Created March 23, 2011 19:33
Show Gist options
  • Save paulononaka/883775 to your computer and use it in GitHub Desktop.
Save paulononaka/883775 to your computer and use it in GitHub Desktop.
A better way to get a system property.
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});
}
@paulononaka
Copy link
Author

Reflection was used because Runtime.getRuntime().exec("getprop " + key) some times causes lock. Also, framework's SystemProperties class is not published in SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment