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

在官方文档中可以查到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 getRadioVersion() instead.
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。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值