获取编程的Andr​​oid手机型号

获取编程的Andr​​oid手机型号

本文介绍了获取编程的Andr​​oid手机型号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法来读取手机型号编程的机器人。

I would like to know if there is a way for reading the Phone Model Programmatically in android.

我想获得像HTC梦,里程碑,蓝宝石或任何...

I would like to get a string like HTC Dream, Milestone, Sapphire or whatever...

感谢:)

推荐答案

不幸的是,在许多流行的设备,该设备的市场名称不可用。例如,三星Galaxy S6中的<$c$c>Build.MODEL可以是SM-G920F,SM-G920I,SM-G920W8等

Unfortunately, on many popular devices, the market name of the device is not available. For example, on the Samsung Galaxy S6 the value of Build.MODEL could be "SM-G920F", "SM-G920I", "SM-G920W8", etc.

我创建了一个小型图书馆,获取设备的市场(消费型)的名字。查看GitHub上的项目用法:

I created a small library that gets the market (consumer friendly) name of a device. See the project on GitHub for usage:

如果你不想使用上述库,那么这是获得一个消费者友好的设备名的最好的解决办法:

If you do not want to use the library above, then this is the best solution for getting a consumer friendly device name:

/** Returns the consumer friendly device name */
public static String getDeviceName() {
    String manufacturer = Build.MANUFACTURER;
    String model = Build.MODEL;
    if (model.startsWith(manufacturer)) {
        return capitalize(model);
    }
    return capitalize(manufacturer) + " " + model;
}

private static String capitalize(String str) {
    if (TextUtils.isEmpty(str)) {
        return str;
    }
    char[] arr = str.toCharArray();
    boolean capitalizeNext = true;
    String phrase = "";
    for (char c : arr) {
        if (capitalizeNext && Character.isLetter(c)) {
            phrase += Character.toUpperCase(c);
            capitalizeNext = false;
            continue;
        } else if (Character.isWhitespace(c)) {
            capitalizeNext = true;
        }
        phrase += c;
    }
    return phrase;
}


这是我的Verizon公司的HTC One M8例如:


Example from my Verizon HTC One M8:

// using method from above
System.out.println(getDeviceName());
// Using https://github.com/jaredrummler/AndroidDeviceNames
System.out.println(DeviceName.getDeviceName());

结果:

HTC6525LVW

的HTC One(M8)

HTC One (M8)

这篇关于获取编程的Andr​​oid手机型号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 05:24