三.非系统开发,反射调用
3.1.getProperty
@SuppressWarnings("finally")
public String getProperty(String key) {
String value = "unknown";
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class, String.class);
value = (String) (get.invoke(c, key, "unknown"));
} catch (Exception e) {
e.printStackTrace();
} finally {
return value;
}
}
3.1.setProperty
public void setProperty(String key, String value) {
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method set = c.getMethod("set", String.class, String.class);
set.invoke(c, key, value);
} catch (Exception e) {
e.printStackTrace();
}
}
RK:android 关于SystemProperties的使用
原文:https://www.cnblogs.com/crushgirl/p/13392501.html