说明
本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
部分参数返回值为default的,会在正式发布的版本中配置。
本模块接口返回设备常量信息,建议应用只调用一次,不需要频繁调用。
一、导入模块
import { deviceInfo } from '@kit.BasicServicesKit';
二、属性
说明
未特殊说明的字段,数据长度最大值为96字节。
系统能力:SystemCapability.Startup.SystemInfo。
权限:以下各项所需要的权限有所不同,详见下表。
名称 | 类型 | 可读 | 可写 | 说明 |
---|---|---|---|---|
deviceType | string | 是 | 否 | 设备类型。详细请参考deviceTypes标签。 元服务API:从API version 11开始,该接口支持在元服务中使用。 示例:phone |
manufacture | string | 是 | 否 | 设备厂家名称。示例: HUAWEI |
brand | string | 是 | 否 | 设备品牌名称。 元服务API:从API version 11开始,该接口支持在元服务中使用。 示例:HUAWEI |
marketName | string | 是 | 否 | 外部产品系列。 示例:HUAWEI Mate 60 Pro |
productSeries | string | 是 | 否 | 产品系列。 示例:ALN |
productModel | string | 是 | 否 | 认证型号。 元服务API:从API version 11开始,该接口支持在元服务中使用。 示例:ALN-AL00 |
softwareModel | string | 是 | 否 | 内部软件子型号。 示例:ALN-AL00 |
hardwareModel | string | 是 | 否 | 硬件版本号。 示例:HL1CMSM |
hardwareProfile(deprecated) | string | 是 | 否 | 硬件Profile。 说明: 从API version 6 开始支持,从API version 9 开始废弃。 示例:default |
serial | string | 是 | 否 | 设备序列号,仅限系统应用使用。 说明:可作为设备唯一识别码。 需要权限:ohos.permission.sec.ACCESS_UDID 示例:序列号随设备差异 |
bootloaderVersion | string | 是 | 否 | Bootloader版本号。 示例:bootloader |
abiList | string | 是 | 否 | 应用二进制接口(Abi)。 示例:arm64-v8a |
securityPatchTag | string | 是 | 否 | 安全补丁级别。 示例:2024/1/1 |
displayVersion | string | 是 | 否 | 产品版本。 示例:ALN-AL00 5.0.0.1(XXX) |
incrementalVersion | string | 是 | 否 | 差异版本号。 示例:default |
osReleaseType | string | 是 | 否 | 系统的发布类型,取值为: - Canary:面向特定开发者发布的早期预览版本,不承诺API稳定性。 - Beta:面向开发者公开发布的Beta版本,不承诺API稳定性。 - Release:面向开发者公开发布的正式版本,承诺API稳定性。 示例:Canary1/Beta2/Release |
osFullName | string | 是 | 否 | 系统版本,版本格式OpenHarmony-x.x.x.x,x为数值。 元服务API:从API version 11开始,该接口支持在元服务中使用。 示例:OpenHarmony-5.0.0.1(Canary1) |
majorVersion | number | 是 | 否 | Major版本号,随主版本更新增加,值为osFullName中的第一位数值,建议直接使用deviceInfo.majorVersion获取,可提升效率,不建议开发者解析osFullName获取。 示例:5 |
seniorVersion | number | 是 | 否 | Senior版本号,随局部架构、重大特性增加,值为osFullName中的第二位数值,建议直接使用deviceInfo.seniorVersion获取,可提升效率,不建议开发者自主解析osFullName获取。 示例:0 |
featureVersion | number | 是 | 否 | Feature版本号,标识规划的新特性版本,值为osFullName中的第三位数值,建议直接使用deviceInfo.featureVersion获取,可提升效率,不建议开发者自主解析osFullName获取。 示例:0 |
buildVersion | number | 是 | 否 | Build版本号,标识编译构建的版本号,值为osFullName中的第四位数值,建议直接使用deviceInfo.buildVersion获取,可提升效率,不建议开发者自主解析osFullName获取。 示例:1 |
sdkApiVersion | number | 是 | 否 | 系统软件API版本。 元服务API:从API version 14开始,该接口支持在元服务中使用。 示例:12 |
firstApiVersion | number | 是 | 否 | 首个版本系统软件API版本。 示例:3 |
versionId | string | 是 | 否 | 版本ID。 由deviceType、manufacture、brand、productSeries、osFullName、productModel、softwareModel、sdkApiVersion、incrementalVersion、buildType拼接组成。 示例:wearable/HUAWEI/HUAWEI/TAS/OpenHarmony-5.0.0.1/TAS-AL00/TAS-AL00/12/default/release:nolog |
buildType | string | 是 | 否 | 构建类型。 示例:release:nolog |
buildUser | string | 是 | 否 | 构建用户。 示例:default |
buildHost | string | 是 | 否 | 构建主机。 示例:default |
buildTime | string | 是 | 否 | 构建时间。 示例:default |
buildRootHash | string | 是 | 否 | 构建版本Hash。 示例:default |
udid7+ | string | 是 | 否 | 设备Udid,仅限系统应用使用。 说明:数据长度为65字节。可作为设备唯一识别码。 需要权限:ohos.permission.sec.ACCESS_UDID 示例:9D6AABD147XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXE5536412 |
distributionOSName10+ | String | 是 | 否 | 发行版系统名称。 示例:OpenHarmony |
distributionOSVersion10+ | String | 是 | 否 | 发行版系统版本号。格式为x.x.x, x是数字 示例:5.0.0.1 |
distributionOSApiVersion10+ | number | 是 | 否 | 发行版系统api版本。 示例:50001 |
distributionOSReleaseType10+ | String | 是 | 否 | 发行版系统类型。 示例:Release |
ODID12+ | String | 是 | 否 | 开发者匿名设备标识符。 ODID值会在以下场景重新生成:手机恢复出厂设置。同一设备上同一个开发者(developerId相同)的应用全部卸载后重新安装时。 ODID生成规则:根据签名信息里developerId解析出的groupId生成,developerId规则为groupId.developerId,若无groupId则取整个developerId作为groupId。同一设备上运行的同一个开发者(developerId相同)的应用,ODID相同。同一个设备上不同开发者(developerId不同)的应用,ODID不同。不同设备上同一个开发者(developerId相同)的应用,ODID不同。不同设备上不同开发者(developerId不同)的应用,ODID不同。 说明:数据长度为37字节。 示例:1234a567-XXXX-XXXX-XXXX-XXXXXXXXXXXX |
三、示例
效果图
TestDeviceInfo.ets代码
import { deviceInfo } from '@kit.BasicServicesKit'let displayVersionInfo: string = deviceInfo.displayVersion; // 产品版本
let osFullNameInfo: string = deviceInfo.osFullName; // 系统版本
let versionIdInfo: string = deviceInfo.versionId; // 版本ID
let deviceTypeInfo: string = deviceInfo.deviceType;
let manufactureInfo: string = deviceInfo.manufacture;
let brandInfo: string = deviceInfo.brand;
let marketNameInfo: string = deviceInfo.marketName;
let productModelInfo: string = deviceInfo.productModel;
let hardwareModelInfo: string = deviceInfo.hardwareModel;
let serialInfo: string = deviceInfo.serial;
let sdkApiVersionInfo: number = deviceInfo.sdkApiVersion;
let buildVersion: number = deviceInfo.buildVersion;
let buildType: string = deviceInfo.buildType;
let osReleaseType: string = deviceInfo.osReleaseType;
let seniorVersion: number = deviceInfo.seniorVersion;
let featureVersion: number = deviceInfo.featureVersion;
let productSeries: string = deviceInfo.productSeries;
let buildTime: string = deviceInfo.buildTime;
let distributionOSApiVersion: number = deviceInfo.distributionOSApiVersion;
let distributionOSReleaseType: string = deviceInfo.distributionOSReleaseType;
let ODID: string = deviceInfo.ODID;console.log(`displayVersionInfo: ${displayVersionInfo}`)
console.log(`osFullNameInfo: ${osFullNameInfo}`)
console.log(`versionIdInfo: ${versionIdInfo}`)
console.log(`deviceTypeInfo: ${deviceTypeInfo}`)
console.log(`manufactureInfo: ${manufactureInfo}`)
console.log(`brandInfo: ${brandInfo}`)
console.log(`marketNameInfo: ${marketNameInfo}`)
console.log(`productModelInfo: ${productModelInfo}`)
console.log(`hardwareModelInfo: ${hardwareModelInfo}`)
console.log(`serialInfo: ${serialInfo}`)
console.log(`sdkApiVersionInfo: ${sdkApiVersionInfo}`)
console.log(`buildVersion: ${buildVersion}`)
console.log(`buildType: ${buildType}`)
console.log(`seniorVersion: ${seniorVersion}`)
console.log(`featureVersion: ${featureVersion}`)
console.log(`productSeries: ${productSeries}`)
console.log(`buildTime: ${buildTime}`)
console.log(`distributionOSApiVersion: ${distributionOSApiVersion}`)
console.log(`distributionOSReleaseType: ${distributionOSReleaseType}`)
console.log(`ODID: ${ODID}`)@Entry
@Component
struct TestDeviceInfo {@State message: string = '设备信息';build() {Scroll() {Column({ space: 16 }) {Text(this.message).id('TestDeviceInfoHelloWorld').fontSize(30).fontWeight(FontWeight.Bold)Text(`displayVersionInfo:${displayVersionInfo}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`osFullNameInfo:${osFullNameInfo}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`versionIdInfo:${versionIdInfo}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`deviceTypeInfo:${deviceTypeInfo}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`manufactureInfo:${manufactureInfo}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`brandInfo:${brandInfo}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`marketNameInfo:${marketNameInfo}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`productModelInfo:${productModelInfo}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`hardwareModelInfo:${hardwareModelInfo}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`serialInfo:${serialInfo}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`sdkApiVersionInfo:${sdkApiVersionInfo}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`buildVersion:${buildVersion}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`buildType:${buildType}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`osReleaseType:${osReleaseType}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`seniorVersion:${seniorVersion}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`featureVersion:${featureVersion}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`productSeries:${productSeries}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`buildTime:${buildTime}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`distributionOSApiVersion:${distributionOSApiVersion}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`distributionOSReleaseType:${distributionOSReleaseType}`).fontSize(20).fontWeight(FontWeight.Medium)Text(`ODID:${ODID}`).fontSize(20).fontWeight(FontWeight.Medium)}}.height('100%').width('100%')}
}