本文转载自:https://blog.csdn.net/wei_lei/article/details/70312512
Android.os.SystemProperties 提供了获取和设置系统属性的方法,但是这个类被隐藏了,应用开发时无法直接访问,可以通过反射的机制进行操作。
public static public String getProperty(String key, String defaultValue) {
String value = defaultValue;
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;
}
}
public static 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();
}
}
getProperty("ro.build.display.id", "unknown");
adb shell
进入 adb shellcd system
进入 system 目录输入 cat build.prop
查看所有系统属性
输入 cat build.prop | grep [指定字符串]
查看所有包含指定字符串的项
Android : 反射机制获取或设置系统属性(SystemProperties)【转】
原文:https://www.cnblogs.com/zzb-Dream-90Time/p/9159409.html