我想知道是否有一种在Android中以编程方式阅读手机模型的方法。

我想要一个像HTC梦想,里程碑,蓝宝石或任何字符串…


当前回答

方法获取电话设备名称

BluetoothAdapter

如果手机不支持蓝牙,那么您必须从构造设备名称

android.os.Build类

下面是获取电话设备名称的示例代码。

public String getPhoneDeviceName() {  
        String name=null;
        // Try to take Bluetooth name
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        if (adapter != null) {
            name = adapter.getName();
        }

        // If not found, use MODEL name
        if (TextUtils.isEmpty(name)) {
            String manufacturer = Build.MANUFACTURER;
            String model = Build.MODEL;
            if (model.startsWith(manufacturer)) {
                name = model;
            } else {
                name = manufacturer + " " + model;
            }
        } 
        return name;
}

其他回答

你可以尝试跟随函数,它会以字符串格式返回你的phoneModel名字。

public String phoneModel() {

    return Build.MODEL;
}

这是我的代码,以获得制造商,品牌名称,Os版本和支持API级别

String manufacturer = Build.MANUFACTURER;

String model = Build.MODEL + " " + android.os.Build.BRAND +" ("
           + android.os.Build.VERSION.RELEASE+")"
           + " API-" + android.os.Build.VERSION.SDK_INT;

if (model.startsWith(manufacturer)) {
    return capitalize(model);
} else {
    return capitalize(manufacturer) + " " + model;
}

输出:

System.out: button press on device name = Lava Alfa L iris(5.0) API-21
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);
    }
Build.DEVICE // The name of the industrial design.

构建。DEVICE为某些设备提供人类可读的名称。模型

Build.DEVICE = OnePlus6
Build.MANUFACTURER = OnePlus
Build.MODEL = ONEPLUS A6003

显然你需要使用https://support.google.com/googleplay/answer/1727131上谷歌的列表

api不会返回任何我期望的东西或设置中的任何东西。对于我的摩托罗拉X,这是我得到的

   Build.MODEL = "XT1053"
   Build.BRAND = "motorola"
   Build.PRODUCT = "ghost"

转到上面提到的Moto x的“幽灵”地图页面,似乎这可以简单一点…