最近正在以某亿级APP源码为模板学习android的各方面内容,包括设计、开发、各种类的使用,已经最重要的就是思路。
在官方文档中可以查到Build类中有如下常量:
public static final String | BOARD | The name of the underlying board, like "goldfish".主板名称 |
public static final String | BOOTLOADER | The system bootloader version number.系统引导程序版本号 |
public static final String | BRAND | The brand (e.g., carrier) the software is customized for, if any.android系统定制商 |
public static final String | CPU_ABI | The name of the instruction set (CPU type + ABI convention) of native code.CPU 和ABI的本地代码指令集 |
public static final String | CPU_ABI2 | The name of the second instruction set (CPU type + ABI convention) of native code. |
public static final String | DEVICE | The name of the industrial design.设备参数 |
public static final String | DISPLAY | A build ID string meant for displaying to the user显示屏参数 |
public static final String | FINGERPRINT | A string that uniquely identifies this build.硬件名 |
public static final String | HARDWARE | The name of the hardware (from the kernel command line or /proc).内核命令行中的硬件名 |
public static final String | HOST | |
public static final String | ID | Either a changelist number, or a label like "M4-rc20".修改版本列表 |
public static final String | MANUFACTURER | The manufacturer of the product/hardware.硬件厂商 |
public static final String | MODEL | The end-user-visible name for the end product.版本 |
public static final String | PRODUCT | The name of the overall product.手机厂商 |
public static final String | RADIO | This field was deprecated in API level 14. The radio firmware version is frequently not available when this class is initialized, leading to a blank or "unknown" value for this string. Use |
public static final String | SERIAL | A hardware serial number, if available. |
public static final String | TAGS | Comma-separated tags describing the build, like "unsigned,debug".描述Build的标签 |
public static final long | TIME | |
public static final String | TYPE | The type of build, like "user" or "eng".Build的类型 |
public static final String | USER | |
通过这些常量就可以获得Android手机的一些设备信息。
例如:
/**
* 检查手机类型, 是否是三星 小米 或 普通root机 普通非root机
*/
public void checkPhoneType() {
// 是否是rom为2.3以上的三星非Google定制手机
String manufacturer = Build.MANUFACTURER;
int sdkVersion = Build.VERSION.SDK_INT;
String model = Build.MODEL;
String displayStr = Build.DISPLAY;
String brand = Build.BRAND;
String phoneInfo = "Product: " + android.os.Build.PRODUCT;
phoneInfo += ", CPU_ABI: " + android.os.Build.CPU_ABI;
phoneInfo += ", TAGS: " + android.os.Build.TAGS;
phoneInfo += ", VERSION_CODES.BASE: "
+ android.os.Build.VERSION_CODES.BASE;
phoneInfo += ", MODEL: " + android.os.Build.MODEL;
phoneInfo += ", SDK: " + android.os.Build.VERSION.SDK;
phoneInfo += ", VERSION.RELEASE: " + android.os.Build.VERSION.RELEASE;
phoneInfo += ", DEVICE: " + android.os.Build.DEVICE;
phoneInfo += ", DISPLAY: " + android.os.Build.DISPLAY;
phoneInfo += ", BRAND: " + android.os.Build.BRAND;
phoneInfo += ", BOARD: " + android.os.Build.BOARD;
phoneInfo += ", FINGERPRINT: " + android.os.Build.FINGERPRINT;
phoneInfo += ", ID: " + android.os.Build.ID;
phoneInfo += ", MANUFACTURER: " + android.os.Build.MANUFACTURER;
phoneInfo += ", USER: " + android.os.Build.USER;
String device = Build.DEVICE;
if (model.startsWith("Lenovo")) {
setLenovoLenovo(true);
}
if ("Meizu".equals(brand)) {
setMZ(true);
}
if ((manufacturer != null && manufacturer.trim().contains("samsung") && sdkVersion >= 9)
&& (model == null || (!model.trim().toLowerCase()
.contains("google") && !model.trim().toLowerCase()
.contains("nexus")))) {
setSamsung(true);
}
// 安卓4.0以上rom
if (sdkVersion >= 14) {
setSdkGreaterThanApi14(true);
}
if (displayStr != null && displayStr.toLowerCase().contains("miui")) {
setMIUI(true);
}
if (brand.equals("Xiaomi") && model.trim().contains("MI 2")) {
setIsXiaomi2S(true);
}
if (brand.equals("Xiaomi") && model.trim().contains("1S")) {
setIsXiaomi2S(true);
}
if (brand.equals("Xiaomi") && model.trim().contains("MI-")) {
setMIUI(true);
}
}
通过这些信息就能区别出手机厂商、品牌和型号信息,从而有针对性的进行操作。
Build类下只有一个方法:getRadioVersion()。
Returns the version string for the radio firmware. May return null (if, for instance, the radio is not currently on).
用于获取无线电固件的版本号,返回值是String。