如何获取Android设备名称?我正在使用HTC欲望。当我通过HTC Sync连接它时,软件显示“HTC Smith”的名称。我想通过代码获取这个名称。

这在Android中是如何实现的呢?


当前回答

你可以使用:

来自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;
}

但请记住,这在某些设备上不起作用。

为了获得Android设备名称,你只需要添加一行代码:

android.os.Build.MODEL;

找到这里:getting-android-device-name

试一试。您可以通过蓝牙获取设备名称。

希望对你有所帮助

public String getPhoneName() {  
        BluetoothAdapter myDevice = BluetoothAdapter.getDefaultAdapter();
        String deviceName = myDevice.getName();     
        return deviceName;
    }

试试这段代码。你会得到android设备名。

public static String getDeviceName() {
    String manufacturer = Build.MANUFACTURER;
    String model = Build.MODEL;
    if (model.startsWith(manufacturer)) {
        return model;
    }
    return manufacturer + " " + model;
}

我通过获取蓝牙名称解决了这个问题,但不是从BluetoothAdapter(需要蓝牙权限)获得的。

代码如下:

Settings.Secure.getString(getContentResolver(), "bluetooth_name");

不需要额外的权限。