如何获取Android设备名称?我正在使用HTC欲望。当我通过HTC Sync连接它时,软件显示“HTC Smith”的名称。我想通过代码获取这个名称。
这在Android中是如何实现的呢?
如何获取Android设备名称?我正在使用HTC欲望。当我通过HTC Sync连接它时,软件显示“HTC Smith”的名称。我想通过代码获取这个名称。
这在Android中是如何实现的呢?
当前回答
为了获得Android设备名称,你只需要添加一行代码:
android.os.Build.MODEL;
找到这里:getting-android-device-name
其他回答
你可以在这里看到答案获得Android手机模型编程
public String getDeviceName() {
String manufacturer = Build.MANUFACTURER;
String model = Build.MODEL;
if (model.startsWith(manufacturer)) {
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);
}
}
@hbhakhra的答案就可以了。
如果你对详细的解释感兴趣,看看Android兼容性定义文档是很有用的。(3.2.2构建参数)
你会发现:
DEVICE - A value chosen by the device implementer containing the development name or code name identifying the configuration of the hardware features and industrial design of the device. The value of this field MUST be encodable as 7-bit ASCII and match the regular expression “^[a-zA-Z0-9_-]+$”. MODEL - A value chosen by the device implementer containing the name of the device as known to the end user. This SHOULD be the same name under which the device is marketed and sold to end users. There are no requirements on the specific format of this field, except that it MUST NOT be null or the empty string (""). MANUFACTURER - The trade name of the Original Equipment Manufacturer (OEM) of the product. There are no requirements on the specific format of this field, except that it MUST NOT be null or the empty string ("").
以下对我有用。
String deviceName = Settings.Global.getString(.getContentResolver(), Settings.Global.DEVICE_NAME);
我不认为这是重复的答案。上面的ppl正在谈论设置安全,为我设置安全是给空,如果我使用设置全局它工作。不管怎样,谢谢你。
我通过获取蓝牙名称解决了这个问题,但不是从BluetoothAdapter(需要蓝牙权限)获得的。
代码如下:
Settings.Secure.getString(getContentResolver(), "bluetooth_name");
不需要额外的权限。
首先,
Adb shell getprop >prop_list.txt
第二,
在prop_list.txt中找到您的设备名称以获得道具名称, 例如,我的设备名称是ro.oppo.market.name
最后,
Adb shell getprop ro.oppo.market.name
D:\winusr\adbl
λ adb shell getprop ro.oppo.market.name
成本R17
D:\winusr\adbl
λ