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

来源:互联网 发布:无线pos数据拦截 编辑:程序博客网 时间:2024/05/04 13:16

最近正在以某亿级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. UsegetRadioVersion() 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以上romif (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。


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 微信转账不还钱怎么办 碳放久了不爱起火怎么办 闻碳火时间久了怎么办 被代运营诈骗怎么办 被上海聚连骗了怎么办? 蓝领贷逾期半年怎么办 淘宝店倒闭售后怎么办 淘宝店铺宝贝被下架怎么办 医院被托管编制怎么办 领码分百万账号异常怎么办 拼多多帐号异常怎么办 qq钱包交易异常怎么办 托管公司跑了怎么办? 花呗退款没到账怎么办 车辆过户了车牌怎么办 货车资格证脱审怎么办 廉租房夫妻离婚怎么办 二手车行驶证怎么办的? 卖二手车后车牌怎么办 房子动迁没过户怎么办? 北京买车指标怎么办 签合同不交社保怎么办 养老保险交重了怎么办 公司克扣员工工资应该怎么办 天猫拒绝退款怎么办 一看书就犯困怎么办 擦了风油精过敏怎么办 擦了清凉油过敏怎么办 脸上擦风油精过敏怎么办 搽了风油精过敏怎么办 背带裤显屁股大怎么办 打底衫肥了怎么办 天猫卖家总是发信息怎么办 房子装修完有味怎么办 房子装修油漆味怎么办 房子装修代款怎么办 房子要装修不懂怎么办 手机淘宝没地区怎么办 qq有不良记录怎么办 账号有不良记录怎么办 qq批量登录冻结怎么办