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

本文介绍了Android系统中Build类包含的各种信息,如设备型号、制造商等,并提供了检查手机类型的示例代码。

最近正在以某亿级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。


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值