• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 设备信息
2
3> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
4> - 从API Version 6开始,该接口不再维护,推荐使用新接口[`@ohos.deviceInfo`](js-apis-device-info.md)进行设备信息查询。
5>
6> - 本模块首批接口从API version 3开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
7
8
9## 导入模块
10
11
12```
13import device from '@system.device';
14```
15
16
17## device.getInfo
18
19getInfo(Object): void
20
21获取当前设备的信息。
22
23> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
24> 在首页的onShow生命周期之前不建议调用device.getInfo接口。
25
26**系统能力:** SystemCapability.Startup.SysInfo
27
28**参数:**
29
30| 参数名 | 类型 | 必填 | 说明 |
31| -------- | -------- | -------- | -------- |
32| success | Function | 否 | 接口调用成功的回调函数。 |
33| fail | Function | 否 | 接口调用失败的回调函数。 |
34| complete | Function | 否 | 接口调用结束的回调函数。 |
35
36success返回值:
37
38| 参数名 | 类型 | 说明 |
39| -------- | -------- | -------- |
40| brand | string | 品牌。 |
41| manufacturer | string | 生产商。 |
42| model | string | 型号。 |
43| product | string | 代号。 |
44| language<sup>4+</sup> | string | 系统语言。 |
45| region<sup>4+</sup> | string | 系统地区。 |
46| windowWidth | number | 可使用的窗口宽度。 |
47| windowHeight | number | 可使用的窗口高度。 |
48| screenDensity<sup>4+</sup> | number | 屏幕密度。 |
49| screenShape<sup>4+</sup> | string | 屏幕形状。可取值:<br/>-&nbsp;rect:方形屏;<br/>-&nbsp;circle:圆形屏。 |
50| apiVersion<sup>4+</sup> | number | 系统API版本号。 |
51| releaseType<sup>4+</sup> | string | 版本发布类型,值为类型+版本号,如Beta1。<br/>类型可能值有:<br/>-&nbsp;Canary:同一apiVersion下,canary版本之间保持API兼容,beta版本不对canary版本兼容。<br/>-&nbsp;Beta:同一apiVersion下,beta版本之间保持API兼容,release版本不对beta版本兼容。<br/>-&nbsp;Release:release版本会保持5个API版本兼容。 |
52| deviceType<sup>4+</sup> | string | 设备类型。 |
53
54fail返回错误代码:
55
56| 错误码 | 说明 |
57| -------- | -------- |
58| 200 | 返回结果中存在无法获得的信息。 |
59
60**示例:**
61
62```
63export default {
64  getInfo() {
65    device.getInfo({
66      success: function(data) {
67        console.log('Device information obtained successfully. Device brand:' + data.brand);
68      },
69      fail: function(data, code) {
70        console.log('Failed to obtain device information. Error code:'+ code + '; Error information: ' + data);
71      },
72    });
73  },
74}
75```