HarmonyOS:查询设备信息

server/2025/2/8 12:38:20/

说明
本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

部分参数返回值为default的,会在正式发布的版本中配置。

本模块接口返回设备常量信息,建议应用只调用一次,不需要频繁调用。

一、导入模块

import { deviceInfo } from '@kit.BasicServicesKit';

二、属性

说明
未特殊说明的字段,数据长度最大值为96字节。

系统能力:SystemCapability.Startup.SystemInfo。

权限:以下各项所需要的权限有所不同,详见下表。

名称类型可读可写说明
deviceTypestring设备类型。详细请参考deviceTypes标签。
元服务API:从API version 11开始,该接口支持在元服务中使用。
示例:phone
manufacturestring设备厂家名称。示例:
HUAWEI
brandstring设备品牌名称。
元服务API:从API version 11开始,该接口支持在元服务中使用。
示例:HUAWEI
marketNamestring外部产品系列。
示例:HUAWEI Mate 60 Pro
productSeriesstring产品系列。
示例:ALN
productModelstring认证型号。
元服务API:从API version 11开始,该接口支持在元服务中使用。
示例:ALN-AL00
softwareModelstring内部软件子型号。
示例:ALN-AL00
hardwareModelstring硬件版本号。
示例:HL1CMSM
hardwareProfile(deprecated)string硬件Profile。
说明:
从API version 6 开始支持,从API version 9 开始废弃。
示例:default
serialstring设备序列号,仅限系统应用使用。
说明:可作为设备唯一识别码。
需要权限:ohos.permission.sec.ACCESS_UDID
示例:序列号随设备差异
bootloaderVersionstringBootloader版本号。
示例:bootloader
abiListstring应用二进制接口(Abi)。
示例:arm64-v8a
securityPatchTagstring安全补丁级别。
示例:2024/1/1
displayVersionstring产品版本。
示例:ALN-AL00 5.0.0.1(XXX)
incrementalVersionstring差异版本号。
示例:default
osReleaseTypestring系统的发布类型,取值为:
- Canary:面向特定开发者发布的早期预览版本,不承诺API稳定性。
- Beta:面向开发者公开发布的Beta版本,不承诺API稳定性。
- Release:面向开发者公开发布的正式版本,承诺API稳定性。
示例:Canary1/Beta2/Release
osFullNamestring系统版本,版本格式OpenHarmony-x.x.x.x,x为数值。
元服务API:从API version 11开始,该接口支持在元服务中使用。
示例:OpenHarmony-5.0.0.1(Canary1)
majorVersionnumberMajor版本号,随主版本更新增加,值为osFullName中的第一位数值,建议直接使用deviceInfo.majorVersion获取,可提升效率,不建议开发者解析osFullName获取。
示例:5
seniorVersionnumberSenior版本号,随局部架构、重大特性增加,值为osFullName中的第二位数值,建议直接使用deviceInfo.seniorVersion获取,可提升效率,不建议开发者自主解析osFullName获取。
示例:0
featureVersionnumberFeature版本号,标识规划的新特性版本,值为osFullName中的第三位数值,建议直接使用deviceInfo.featureVersion获取,可提升效率,不建议开发者自主解析osFullName获取。
示例:0
buildVersionnumberBuild版本号,标识编译构建的版本号,值为osFullName中的第四位数值,建议直接使用deviceInfo.buildVersion获取,可提升效率,不建议开发者自主解析osFullName获取。
示例:1
sdkApiVersionnumber系统软件API版本。
元服务API:从API version 14开始,该接口支持在元服务中使用。
示例:12
firstApiVersionnumber首个版本系统软件API版本。
示例:3
versionIdstring版本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
buildTypestring构建类型。
示例:release:nolog
buildUserstring构建用户。
示例:default
buildHoststring构建主机。
示例:default
buildTimestring构建时间。
示例:default
buildRootHashstring构建版本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%')}
}

http://www.ppmy.cn/server/165955.html

相关文章

树莓派5添加摄像头 在C++下调用opencv

由于树莓派5 os系统升级,正常libcamera创建对象每次失败。 改如下方法成功。 1 创建管道 rpicam-vid -t 0 --codec mjpeg -o udp://127.0.0.1:8554 > /dev/null 2>&1 2 opencv从管道里读取 #include <opencv2/opencv.hpp> #include <iostream>int mai…

Docker Desktop安装kubernetes时一直在Starting:Kubernetes failed to start

原因&#xff1a;由于墙的问题&#xff0c;导致拉取国外的K8s镜像失败 解决&#xff1a; 下载 k8s-for-docker-desktop 选中自己的kubernetes 版本 下载zip包 PowerShell运行load_images.ps1文件 重启docker kubernetes运行成功

day 41 51中断系统以及定时器

1.中断 1.寄存器&#xff1a;具有固定地址值的内存空间&#xff0c;对于soc来说具有特殊的功能的变量。 2.中断&#xff1a;当cpu处理事件时&#xff0c;外界发生紧急请求&#xff0c;要求cpu暂停当前工作去处理这个紧急事件&#xff0c;处理完之后回到原来中断的地方&#xf…

小白如何制作精致 PPT?免费 Office 插件来帮忙

微软 Office Plus 是由微软中国团队精心打造的免费 Word、Excel 和 PPT 模板素材网站。在这里&#xff0c;您可以轻松获取各类高质量的模板&#xff0c;以及一款微软官方 PPT 插件。这款插件能够将 Office Plus 的丰富模板直接内嵌到 PPT 中&#xff0c;极大地提升了制作演示文…

Scala语言的人工智能

Scala语言的人工智能探索 引言 在现代软件开发的领域中&#xff0c;人工智能&#xff08;AI&#xff09;正在以惊人的速度发展和扩展。无论是在自然语言处理、计算机视觉还是自动化决策系统&#xff0c;人工智能技术都在不断革新。而在众多编程语言中&#xff0c;Scala以其独…

Linux学习笔记17---UART 串口通信实验

不管是单片机开发还是嵌入式 Linux 开发&#xff0c;串口都是最常用到的外设。可以通过串口将开发板与电脑相连&#xff0c;然后在电脑上通过串口调试助手来调试程序。还有很多的模块&#xff0c;比如蓝牙、 GPS、 GPRS 等都使用的串口来与主控进行通信的&#xff0c;在嵌入式…

电脑运行黑屏是什么原因?原因及解决方法

电脑运行黑屏是指电脑在正常开机或使用过程中&#xff0c;突然出现屏幕变黑&#xff0c;无法显示任何内容的现象。这种现象可能会给用户带来很多不便&#xff0c;甚至造成数据丢失或硬件损坏。那么&#xff0c;电脑运行黑屏是什么原因呢&#xff1f;下面我们将分析几种可能的原…

Android 中实现 PDF 预览三种方式

目录 1. 使用第三方库 PdfRenderer&#xff08;适用于 Android 5.0 及以上&#xff09; 步骤&#xff1a;2. 使用第三方库 MuPDF步骤&#xff1a;3. 使用第三方库 PdfiumAndroid步骤&#xff1a; 1. 使用第三方库 PdfRenderer&#xff08;适用于 Android 5.0 及以上&#xff09…