如何获取Android设备名称?我正在使用HTC欲望。当我通过HTC Sync连接它时,软件显示“HTC Smith”的名称。我想通过代码获取这个名称。
这在Android中是如何实现的呢?
如何获取Android设备名称?我正在使用HTC欲望。当我通过HTC Sync连接它时,软件显示“HTC Smith”的名称。我想通过代码获取这个名称。
这在Android中是如何实现的呢?
当前回答
为了获得Android设备名称,你只需要添加一行代码:
android.os.Build.MODEL;
找到这里:getting-android-device-name
其他回答
我通过获取蓝牙名称解决了这个问题,但不是从BluetoothAdapter(需要蓝牙权限)获得的。
代码如下:
Settings.Secure.getString(getContentResolver(), "bluetooth_name");
不需要额外的权限。
以下对我有用。
String deviceName = Settings.Global.getString(.getContentResolver(), Settings.Global.DEVICE_NAME);
我不认为这是重复的答案。上面的ppl正在谈论设置安全,为我设置安全是给空,如果我使用设置全局它工作。不管怎样,谢谢你。
你可以使用:
来自android doc:
制造商: 字符串制造商 产品/硬件的制造商。 模型: 字符串模型 最终产品的最终用户可见的名称。 设备: 字符串的设备 工业设计的名称。
举个例子:
String deviceName = android.os.Build.MANUFACTURER + " " + android.os.Build.MODEL;
//to add to textview
TextView textView = (TextView) findViewById(R.id.text_view);
textView.setText(deviceName);
此外,在Build类中有很多你可以使用的属性,比如:
android操作系统。棋盘构建。 android操作系统。布兰德构建。 android操作系统。BOOTLOADER构建。 显示屏构建android操作系统。。 android操作系统。CPU_ABI构建。 android os。构建的广告。 os硬件构建android。 android操作系统。ID构建。
还有其他方法可以在不使用Build类的情况下获取设备名称(通过蓝牙)。
更新 你可以很容易地从建筑道具中取回设备。
static String GetDeviceName() {
Process p;
String propvalue = "";
try {
p = new ProcessBuilder("/system/bin/getprop", "ro.semc.product.name").redirectErrorStream(true).start();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
propvalue = line;
}
p.destroy();
} catch (IOException e) {
e.printStackTrace();
}
return propvalue;
}
但请记住,这在某些设备上不起作用。
尝试了这些库,但没有按照我的期望工作,并给出了绝对错误的名称。
所以我自己用同样的数据创建了这个库。 这是链接
AndroidPhoneNamesFinder
要使用这个库,只需添加这个来实现
implementation 'com.github.aishik212:AndroidPhoneNamesFinder:v1.0.2'
然后使用下面的kotlin代码
DeviceNameFinder.getPhoneValues(this, object : DeviceDetailsListener
{
override fun details(doQuery: DeviceDetailsModel?)
{
super.details(doQuery)
Log.d(TAG, "details: "+doQuery?.calculatedName)
}
})
这些是您将从DeviceDetailsModel中获得的值
val brand: String? #This is the brandName of the Device
val commonName: String?, #This is the most common Name of the Device
val codeName: String?, #This is the codeName of the Device
val modelName: String?, #This is the another uncommon Name of the Device
val calculatedName: String?, #This is the special name that this library tries to create from the above data.
Android模拟器示例-
brand=Google
commonName=Google Android Emulator
codeName=generic_x86_arm
modelName=sdk_gphone_x86
calculatedName=Google Android Emulator