您的位置:首页 > 产品设计 > UI/UE

android.os.Build的一些使用方法

2015-05-06 14:37 274 查看
最近正在以某亿级APP源码为模板学习android的各方面内容,包括设计、开发、各种类的使用,已经最重要的就是思路。

在官方文档中可以查到Build类中有如下常量:

public static final StringBOARDThe name of the underlying board, like "goldfish".主板名称
public static final StringBOOTLOADERThe system bootloader version number.系统引导程序版本号
public static final StringBRANDThe brand (e.g., carrier) the software is customized for, if any.android系统定制商
public static final StringCPU_ABIThe name of the instruction set (CPU type + ABI convention) of native code.CPU 和ABI的本地代码指令集
public static final StringCPU_ABI2The name of the second instruction set (CPU type + ABI convention) of native code.
public static final StringDEVICEThe name of the industrial design.设备参数
public static final StringDISPLAYA build ID string meant for displaying to the user显示屏参数
public static final StringFINGERPRINTA string that uniquely identifies this build.硬件名
public static final StringHARDWAREThe name of the hardware (from the kernel command line or /proc).内核命令行中的硬件名
public static final StringHOST
public static final StringIDEither a changelist number, or a label like "M4-rc20".修改版本列表
public static final StringMANUFACTURERThe manufacturer of the product/hardware.硬件厂商
public static final StringMODELThe end-user-visible name for the end product.版本
public static final StringPRODUCTThe name of the overall product.手机厂商
public static final StringRADIOThis 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
getRadioVersion()
instead.
public static final StringSERIALA hardware serial number, if available.
public static final StringTAGSComma-separated tags describing the build, like "unsigned,debug".描述Build的标签
public static final longTIME
public static final StringTYPEThe type of build, like "user" or "eng".Build的类型
public static final StringUSER
通过这些常量就可以获得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。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: