Build类

一、类结构:

java.lang.Object
android.os.Build

二、类概述:从系统属性中提取设备硬件和版本信息。

三、内部类:

1、Build.VERSION 各种版本字符串

2、Build.VERSION_CODES 目前已知的版本代码的枚举类

四、常量:UNKNOWN 当一个版本属性不知道时所设定的值。其字符串值为"unknown" .

五、构造方法:Build()

六、静态属性

1、BOARD 主板:The name of the underlying board, like "goldfish".

2、BOOTLOADER 系统启动程序版本号:The system bootloader version number.

3、BRAND 系统定制商:The consumer-visible brand with which the product/hardware will be associated, if any.

4、CPU_ABI cpu指令集:The name of the instruction set (CPU type + ABI convention) of native code.

5、CPU_ABI2 cpu指令集2:The name of the second instruction set (CPU type + ABI convention) of native code.

6、DEVICE 设备参数:The name of the industrial design.

7、DISPLAY 显示屏参数:A build ID string meant for displaying to the user

8、FINGERPRINT 唯一识别码:A string that uniquely identifies this build. Do not attempt to parse this value.

9、HARDWARE 硬件名称:The name of the hardware (from the kernel command line or /proc).

10、HOST

11、ID 修订版本列表:Either a changelist number, or a label like "M4-rc20".

12、MANUFACTURER 硬件制造商:The manufacturer of the product/hardware.

13、MODEL 版本即最终用户可见的名称:The end-user-visible name for the end product.

14、PRODUCT 整个产品的名称:The name of the overall product.

15、RADIO 无线电固件版本:The radio firmware version number. 在API14后已过时。使用getRadioVersion()代替。

16、SERIAL 硬件序列号:A hardware serial number, if available. Alphanumeric only, case-insensitive.

17、TAGS 描述build的标签,如未签名,debug等等。:Comma-separated tags describing the build, like "unsigned,debug".

18、TIME

19、TYPE build的类型:The type of build, like "user" or "eng".

20、USER

七、公共方法:

public static String getRadioVersion() 获取无线电固件版本

八、测试示例:

package com.home.build;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {
	private TextView showText;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		showText = (TextView) findViewById(R.id.main_tv);
		showText.setText(getDeviceInfo());
	}

	/**
	 * 获取设备信息
	 * 
	 * @return
	 */
	private String getDeviceInfo() {
		StringBuffer sb = new StringBuffer();
		sb.append("主板:" + Build.BOARD);
		sb.append("\n系统启动程序版本号:" + Build.BOOTLOADER);
		sb.append("\n系统定制商:" + Build.BRAND);
		sb.append("\ncpu指令集:" + Build.CPU_ABI);
		sb.append("\ncpu指令集2" + Build.CPU_ABI2);
		sb.append("\n设置参数:" + Build.DEVICE);
		sb.append("\n显示屏参数:" + Build.DISPLAY);
		sb.append("\n无线电固件版本:" + Build.getRadioVersion());
		sb.append("\n硬件识别码:" + Build.FINGERPRINT);
		sb.append("\n硬件名称:" + Build.HARDWARE);
		sb.append("\nHOST:" + Build.HOST);
		sb.append("\n修订版本列表:" + Build.ID);
		sb.append("\n硬件制造商:" + Build.MANUFACTURER);
		sb.append("\n版本:" + Build.MODEL);
		sb.append("\n硬件序列号:" + Build.SERIAL);
		sb.append("\n手机制造商:" + Build.PRODUCT);
		sb.append("\n描述Build的标签:" + Build.TAGS);
		sb.append("\nTIME:" + Build.TIME);
		sb.append("\nbuilder类型:" + Build.TYPE);
		sb.append("\nUSER:" + Build.USER);
		return sb.toString();
	}

}


### Java 中 `build()` 方法的使用 `build()` 方法通常用于流利接口模式(Fluent Interface Pattern),特别是在构建复杂对象时提供一种简洁而直观的方式。通过这种方式可以创建不可变的对象实例,同时保持代码的可读性和灵活性。 #### 构建器模式简介 在Java中,为了简化复杂的对象初始化过程并提高代码质量,引入了Builder设计模式。该模式允许开发者定义一个内部静态作为外部的建造者,并利用链式调用来设置各个成员变量,在最后一步调用`build()`来完成整个对象的组装[^3]。 #### 使用场景 当需要频繁地创建具有多个参数组合的不同配置版本的对象时,采用这种模式能够显著减少冗余代码量,同时也使得API更加友好易懂。 #### 示例代码展示 下面是一个简单的例子展示了如何在一个自定义中应用builder模式: ```java public class User { private final String name; private final int age; private final String sex; // 私有化构造函数防止直接new对象 private User(UserBuilder builder){ this.name = builder.name; this.age = builder.age; this.sex = builder.sex; } @Override public String toString(){ return "User{" + "name='" + name + '\'' + ", age=" + age + ", sex='" + sex + '\'' + '}'; } // 定义静态内部作为Builder public static class UserBuilder{ private String name; private int age; private String sex; public UserBuilder name(String val){this.name=val;return this;} public UserBuilder age(int val){this.age=val;return this;} public UserBuilder sex(String val){this.sex=val;return this;} // 调用父私有的构造方法生成最终产品 public User build(){return new User(this);} } } ``` 测试上述实现的方法如下所示: ```java public class TestL { public static void main(String[] args) { User user = User.UserBuilder() .name("Alice") .age(28) .sex("Female") .build(); System.out.println(user); } } ``` 这段程序会输出似于这样的字符串表示形式:“User{name='Alice', age=28, sex='Female'}”。 对于更高级的应用场合比如处理大量数据流操作,则可以通过集成Stream API 来进一步增强功能特性。例如,如果想要基于某些条件过滤掉不符合要求的数据项后再进行聚合运算等操作,就可以考虑借助于`Stream.Builder<T>`所提供的工具集[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值