鸿蒙语言基础类库:【@system.device (设备信息)】

设备信息

说明:

  • 从API Version 6开始,该接口不再维护,推荐使用新接口[@ohos.deviceInfo]进行设备信息查询。
  • 本模块首批接口从API version 3开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

import device from '@system.device';

device.getInfo

getInfo(Object): void

获取当前设备的信息。

说明: 在首页的onShow生命周期之前不建议调用device.getInfo接口。

系统能力: SystemCapability.Startup.SysInfo

参数:

参数名 类型 必填 说明
success Function 接口调用成功的回调函数。
fail Function 接口调用失败的回调函数。
complete Function 接口调用结束的回调函数。

success返回值:

参数名 类型 说明
brand string 品牌。
manufacturer string 生产商。
model string 型号。
product string 代号。
language4+ string 系统语言。
region4+ string 系统地区。
windowWidth number 可使用的窗口宽度。
windowHeight number 可使用的窗口高度。
screenDensity4+ number 屏幕密度。
screenShape4+ string 屏幕形状。可取值: - rect:方形屏; - circle:圆形屏。
apiVersion4+ number 系统API版本号。
releaseType4+ string 版本发布类型,值为类型+版本号,如Beta1。 类型可能值有: - Canary:同一apiVersion下,canary版本之间保持API兼容,beta版本不对canary版本兼容。 - Beta:同一apiVersion下,beta版本之间保持API兼容,release版本不对beta版本兼容。 - Release:release版本会保持5个API版本兼容。
deviceType4+ string 设备类型。

fail返回错误代码:

错误码 说明
200 返回结果中存在无法获得的信息。

示例:

export default {    
  getInfo() {        
    device.getInfo({            
      success: function(data) {                
        console.log('Device information obtained successfully. Device brand:' + data.brand);            
      },            
      fail: function(data, code) {                
        console.log('Failed to obtain device information. Error code:'+ code + '; Error information: ' + data);            
      },        
    });    
  },
}
相关推荐
恋猫de小郭6 分钟前
鸿蒙版 React Native 正式开源,ohos_react_native 了解一下
react native·react.js·harmonyos
OH五星上将2 小时前
OpenHarmony(鸿蒙南向开发)——小型系统芯片移植指南(二)
驱动开发·harmonyos·内存管理·openharmony·鸿蒙内核·鸿蒙源码·鸿蒙移植
让开,我要吃人了2 小时前
OpenHarmony鸿蒙开发( Beta5.0)智能油烟机开发实践
驱动开发·嵌入式硬件·华为·移动开发·harmonyos·鸿蒙·openharmony
OH五星上将2 小时前
OpenHarmony(鸿蒙南向开发)——轻量系统芯片移植指南(二)
嵌入式硬件·移动开发·harmonyos·移植·openharmony·鸿蒙开发
Andy醒11 小时前
HarmonyOS开发之使用Picker(从相册选择图片),并且通过Swiper组件实现图片预览
harmonyos·鸿蒙
张帅涛_66621 小时前
HarmonyOS开发之全局状态管理
华为·harmonyos
让开,我要吃人了21 小时前
HarmonyOS开发实战( Beta5.0)蓝牙实现服务端和客户端通讯详解
开发语言·前端·华为·移动开发·harmonyos·鸿蒙·鸿蒙系统
让开,我要吃人了1 天前
HarmonyOS应用开发( Beta5.0)HOS-用户认证服务:面部识别
服务器·前端·华为·移动开发·嵌入式·harmonyos·鸿蒙
让开,我要吃人了1 天前
HarmonyOS开发实战( Beta5.0)橡皮擦案例实践详解
开发语言·前端·华为·移动开发·harmonyos·鸿蒙·鸿蒙系统
ImomoTo1 天前
HarmonyOS学习(十一)——安全管理
学习·安全·harmonyos·arkts·arkui