例如,在我的 Xperia mini 手机上,
-
建造模型 http://developer.android.com/reference/android/os/Build.html#MODEL回报'st15i'
-
建造.制造商 http://developer.android.com/reference/android/os/Build.html#MANUFACTURER回报'索尼爱立信'
但我想得到“索尼爱立信 xperia mini”对于这款手机。
是否可以?
对于该特定手机(也许还有许多其他索尼爱立信手机),您只能通过读取您提到的系统属性来获取真实的设备名称:ro.semc.product.model
Since android.os.SystemProperties
类对公共 API 是隐藏的,您将需要使用反射(或 execgetprop ro.semc.product.model
命令和抓取它的输出 https://stackoverflow.com/a/3772339/648313):
public String getSonyEricssonDeviceName() {
String model = getSystemProperty("ro.semc.product.model");
return (model == null) ? "" : model;
}
private String getSystemProperty(String propName) {
Class<?> clsSystemProperties = tryClassForName("android.os.SystemProperties");
Method mtdGet = tryGetMethod(clsSystemProperties, "get", String.class);
return tryInvoke(mtdGet, null, propName);
}
private Class<?> tryClassForName(String className) {
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
return null;
}
}
private Method tryGetMethod(Class<?> cls, String name, Class<?>... parameterTypes) {
try {
return cls.getDeclaredMethod(name, parameterTypes);
} catch (Exception e) {
return null;
}
}
@SuppressWarnings("unchecked")
private <T> T tryInvoke(Method m, Object object, Object... args) {
try {
return (T) m.invoke(object, args);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (Exception e) {
return null;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)