我想知道是否有一种在Android中以编程方式阅读手机模型的方法。
我想要一个像HTC梦想,里程碑,蓝宝石或任何字符串…
我想知道是否有一种在Android中以编程方式阅读手机模型的方法。
我想要一个像HTC梦想,里程碑,蓝宝石或任何字符串…
当前回答
String deviceName = android.os.Build.MODEL; // returns model name
String deviceManufacturer = android.os.Build.MANUFACTURER; // returns manufacturer
使用以下方法以编程方式获取模型和制造商
public String getDeviceName() {
String manufacturer = Build.MANUFACTURER;
String model = Build.MODEL;
if (model.toLowerCase().startsWith(manufacturer.toLowerCase())) {
return capitalize(model);
} else {
return capitalize(manufacturer) + " " + model;
}
}
private String capitalize(String s) {
if (s == null || s.length() == 0) {
return "";
}
char first = s.charAt(0);
if (Character.isUpperCase(first)) {
return s;
} else {
return Character.toUpperCase(first) + s.substring(1);
}
其他回答
事实上,这不是百分之百正确的。这可以为您提供模型(有时是数字)。 将为您提供手机制造商(HTC部分您的请求):
Build.MANUFACTURER
产品名称:
Build.PRODUCT
我使用下面的代码来获取完整的设备名称。它获得模型和制造商字符串并连接它们,除非模型字符串已经包含制造商名称(在一些手机上):
public String getDeviceName() {
String manufacturer = Build.MANUFACTURER;
String model = Build.MODEL;
if (model.toLowerCase().startsWith(manufacturer.toLowerCase())) {
return capitalize(model);
} else {
return capitalize(manufacturer) + " " + model;
}
}
private String capitalize(String s) {
if (s == null || s.length() == 0) {
return "";
}
char first = s.charAt(0);
if (Character.isUpperCase(first)) {
return s;
} else {
return Character.toUpperCase(first) + s.substring(1);
}
}
以下是我从用户那里得到的一些设备名称示例:
三星GT-S5830L 摩托罗拉MB860 索尼爱立信LT18i LGE LG-P500 HTC Desire V HTC野火S A510e ...
是的:Build.MODEL。
对于谁谁寻找完整的属性列表构建这里是一个索尼Z1 Compact的例子:
Build.BOARD = MSM8974
Build.BOOTLOADER = s1
Build.BRAND = Sony
Build.CPU_ABI = armeabi-v7a
Build.CPU_ABI2 = armeabi
Build.DEVICE = D5503
Build.DISPLAY = 14.6.A.1.236
Build.FINGERPRINT = Sony/D5503/D5503:5.1.1/14.6.A.1.236/2031203XXX:user/release-keys
Build.HARDWARE = qcom
Build.HOST = BuildHost
Build.ID = 14.6.A.1.236
Build.IS_DEBUGGABLE = false
Build.MANUFACTURER = Sony
Build.MODEL = D5503
Build.PRODUCT = D5503
Build.RADIO = unknown
Build.SERIAL = CB5A1YGVMT
Build.SUPPORTED_32_BIT_ABIS = [Ljava.lang.String;@3dd90541
Build.SUPPORTED_64_BIT_ABIS = [Ljava.lang.String;@1da4fc3
Build.SUPPORTED_ABIS = [Ljava.lang.String;@525f635
Build.TAGS = release-keys
Build.TIME = 144792559XXXX
Build.TYPE = user
Build.UNKNOWN = unknown
Build.USER = BuildUser
你可以在调试模式下使用kotlin的“evaluate expression”对话框轻松列出这些属性:
android.os.Build::class.java.fields.map { "Build.${it.name} = ${it.get(it.name)}"}.joinToString("\n")
您可以使用以下代码获取品牌名称和 设备的品牌型号。
String brand = Build.BRAND; // for getting BrandName
String model = Build.MODEL; // for getting Model of the device