[##HarmonyOS Next实战##HarmonyOS SDK应用服务##教育##]
核心概念:
@ohos.deviceInfo (设备信息)
该模块提供终端设备信息查询,开发者不可配置。
注意:该模块接口返回设备常量信息,建议应用只调用一次,不需要频繁调用。
导入模块:
import { deviceInfo } from '@kit.BasicServicesKit';
实战代码
import { deviceInfo } from '@kit.BasicServicesKit';
@Entry
@Component
struct DeviceInfoPage {
@State deviceType: ResourceStr = '';
@State manufacture: ResourceStr = '';
@State brand: ResourceStr = '';
@State marketName: ResourceStr = '';
@State productSeries: ResourceStr = '';
@State productModel: ResourceStr = '';
@State productModelAlias: ResourceStr = '';
@State odid: ResourceStr = '';
@State sdkApiVersion: number = 0;
build() {
Column({ space: 6 }) {
Text('DeviceInfoPage')
.fontSize(24)
.fontWeight(FontWeight.Bold)
Button('getDeviceInfo')
.onClick(() => {
this.getDeviceInfo()
})
Text('设备类型:' + this.deviceType)
Text('厂家名称:' + this.manufacture)
Text('品牌名称:' + this.brand)
Text('外部产品系列:' + this.marketName)
Text('产品型号:' + this.productModel)
Text('odid:' + this.odid)
Text('sdkApiVersion:' + this.sdkApiVersion)
}
.height('100%')
.width('100%')
}
getDeviceInfo() {
//设备类型,示例:phone
this.deviceType = deviceInfo.deviceType;
//厂家名称,示例:HUAWEI
this.manufacture = deviceInfo.manufacture;
//品牌名称,示例:HUAWEI
this.brand = deviceInfo.brand;
//外部产品系列,示例:HUAWEI Mate 60
this.marketName = deviceInfo.marketName;
//产品系列,示例:ALN
this.productSeries = deviceInfo.productSeries;
//认证型号,示例:TAS-AL00
this.productModel = deviceInfo.productModel;
//认证型号别名,示例:TAS-AL00
this.productModelAlias = deviceInfo.productModelAlias;
//内部软件子型号,示例:ALN-AL00
let softwareModelInfo: string = deviceInfo.softwareModel;
//硬件版本号。示例:HL1CMSM
let hardwareModelInfo: string = deviceInfo.hardwareModel;
//设备序列号SN(Serial Number)。
let serialInfo: string = deviceInfo.serial;
//Bootloader版本号。示例:bootloader
let bootloaderVersionInfo: string = deviceInfo.bootloaderVersion;
//应用二进制接口(Abi)。示例:arm64-v8a
let abiListInfo: string = deviceInfo.abiList;
let securityPatchTagInfo: string = deviceInfo.securityPatchTag;
// 输出结果:the value of the securityPatchTag is :2021/01/01
console.info('the value of the deviceInfo securityPatchTag is :' + securityPatchTagInfo);
//产品版本。示例:ALN-AL00 5.0.0.1(XXX)
let displayVersionInfo: string = deviceInfo.displayVersion;
// 输出结果:the value of the displayVersion is :XXX X.X.X.X
console.info('the value of the deviceInfo displayVersion is :' + displayVersionInfo);
let incrementalVersionInfo: string = deviceInfo.incrementalVersion;
// 输出结果:the value of the incrementalVersion is :default
console.info('the value of the deviceInfo incrementalVersion is :' + incrementalVersionInfo);
let osReleaseTypeInfo: string = deviceInfo.osReleaseType;
// 输出结果:the value of the osReleaseType is :Release
console.info('the value of the deviceInfo osReleaseType is :' + osReleaseTypeInfo);
//系统版本,版本格式OpenHarmony-x.x.x.x,x为数值。
let osFullNameInfo: string = deviceInfo.osFullName;
// 输出结果:the value of the osFullName is :OpenHarmony-5.0.0.1
console.info('the value of the deviceInfo osFullName is :' + osFullNameInfo);
let majorVersionInfo: number = deviceInfo.majorVersion;
// 输出结果:the value of the majorVersion is :5
console.info('the value of the deviceInfo majorVersion is :' + majorVersionInfo);
let seniorVersionInfo: number = deviceInfo.seniorVersion;
// 输出结果:the value of the seniorVersion is :0
console.info('the value of the deviceInfo seniorVersion is :' + seniorVersionInfo);
let featureVersionInfo: number = deviceInfo.featureVersion;
// 输出结果:the value of the featureVersion is :0
console.info('the value of the deviceInfo featureVersion is :' + featureVersionInfo);
let buildVersionInfo: number = deviceInfo.buildVersion;
// 输出结果:the value of the buildVersion is :1
console.info('the value of the deviceInfo buildVersion is :' + buildVersionInfo);
//系统软件API版本。示例:12
this.sdkApiVersion = deviceInfo.sdkApiVersion;
let firstApiVersionInfo: number = deviceInfo.firstApiVersion;
// 输出结果:the value of the firstApiVersion is :3
console.info('the value of the deviceInfo firstApiVersion is :' + firstApiVersionInfo);
let versionIdInfo: string = deviceInfo.versionId;
// 输出结果:the value of the versionId is :wearable/HUAWEI/HUAWEI/TAS/OpenHarmony-5.0.0.1/TAS-AL00/TAS-AL00/12/default/release:nolog
console.info('the value of the deviceInfo versionId is :' + versionIdInfo);
let buildTypeInfo: string = deviceInfo.buildType;
// 输出结果:the value of the buildType is :default
console.info('the value of the deviceInfo buildType is :' + buildTypeInfo);
let buildUserInfo: string = deviceInfo.buildUser;
// 输出结果:the value of the buildUser is :default
console.info('the value of the deviceInfo buildUser is :' + buildUserInfo);
let buildHostInfo: string = deviceInfo.buildHost;
// 输出结果:the value of the buildHost is :default
console.info('the value of the deviceInfo buildHost is :' + buildHostInfo);
let buildTimeInfo: string = deviceInfo.buildTime;
// 输出结果:the value of the buildTime is :default
console.info('the value of the deviceInfo buildTime is :' + buildTimeInfo);
let buildRootHashInfo: string = deviceInfo.buildRootHash;
// 输出结果:the value of the buildRootHash is :default
console.info('the value of the deviceInfo buildRootHash is :' + buildRootHashInfo);
let udid: string = deviceInfo.udid;
// 输出结果:the value of the udid is :9D6AABD147XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXE5536412
console.info('the value of the deviceInfo udid is :' + udid);
let distributionOSName: string = deviceInfo.distributionOSName
// 输出结果:the value of the distributionOSName is :OpenHarmony
console.info('the value of the deviceInfo distributionOSName is :' + distributionOSName);
let distributionOSVersion: string = deviceInfo.distributionOSVersion
// 输出结果:the value of the distributionOSVersion is :5.0.0
console.info('the value of the deviceInfo distributionOSVersion is :' + distributionOSVersion);
let distributionOSApiVersion: number = deviceInfo.distributionOSApiVersion
// 输出结果:the value of the distributionOSApiVersion is :500001
console.info('the value of the deviceInfo distributionOSApiVersion is :' + distributionOSApiVersion);
let distributionOSApiName: string = deviceInfo.distributionOSApiName
console.info('the value of the deviceInfo distributionOSApiName is :' + distributionOSApiName);
let distributionOSReleaseType: string = deviceInfo.distributionOSReleaseType
// 输出结果:the value of the distributionOSReleaseType is :Release
console.info('the value of the deviceInfo distributionOSReleaseType is :' + distributionOSReleaseType);
//开发者匿名设备标识符。示例:1234a567-XXXX-XXXX-XXXX-XXXXXXXXXXXX
this.odid = deviceInfo.ODID;
//硬盘序列号。
let diskSN: string = deviceInfo.diskSN;
// 输出结果:the value of the deviceInfo diskSN is :2502EM400567
console.info('the value of the deviceInfo diskSN is :' + diskSN);
}
}