android里有个命令,可以获取当前属性:
adb shell getprop ro.hardware
但在Android SDK里没有这个函数,属于系统模块android.os.SystemProperties,可以通过java的反射机制获得
static public String getprop(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) { Log.d(TAG, "get property error, " + e.getMessage()); } Log.d(TAG, "get property, " + key + " = " + value); return value; }
时间: 2024-10-04 16:12:11