1# @ohos.enterprise.deviceInfo(设备信息管理)(系统接口)
2
3本模块提供企业设备信息管理能力,包括获取设备序列号等。
4
5> **说明:**
6>
7> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9> 本模块接口仅可在Stage模型下使用。
10>
11> 本模块接口仅对[设备管理应用](../../mdm/mdm-kit-guide.md#功能介绍)开放,需将[设备管理应用激活](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin)后调用,实现相应功能。
12>
13> 当前页面仅包含本模块的系统接口,其他公开接口参见。其他公开接口参见[@ohos.enterprise.deviceInfo](js-apis-enterprise-deviceInfo.md)。
14
15## 导入模块
16
17```ts
18import { deviceInfo } from '@kit.MDMKit';
19```
20
21## deviceInfo.getDeviceSerial
22
23getDeviceSerial(admin: Want, callback: AsyncCallback<string>): void
24
25指定设备管理应用获取设备序列号,使用callback异步回调。
26
27**需要权限:** ohos.permission.ENTERPRISE_GET_DEVICE_INFO
28
29**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
30
31**参数:**
32
33| 参数名      | 类型                                       | 必填   | 说明                       |
34| -------- | ---------------------------------------- | ---- | ------------------------------- |
35| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
36| callback | AsyncCallback<string>            | 是    | 回调函数。当接口调用成功,err为null,data为设备序列号,否则err为错误对象。       |
37
38**错误码**:
39
40以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
41
42| 错误码ID | 错误信息                                                                       |
43| ------- | ---------------------------------------------------------------------------- |
44| 9200001 | The application is not an administrator application of the device.            |
45| 9200002 | The administrator application does not have permission to manage the device. |
46| 201 | Permission verification failed. The application does not have the permission required to call the API. |
47| 202 | Permission verification failed. A non-system application calls a system API. |
48| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
49
50**示例:**
51
52```ts
53import { Want } from '@kit.AbilityKit';
54let wantTemp: Want = {
55  bundleName: 'com.example.myapplication',
56  abilityName: 'EntryAbility',
57};
58
59deviceInfo.getDeviceSerial(wantTemp, (err, result) => {
60  if (err) {
61    console.error(`Failed to get device serial. Code: ${err.code}, message: ${err.message}`);
62    return;
63  }
64  console.info(`Succeeded in getting device serial, result : ${result}`);
65});
66```
67
68## deviceInfo.getDeviceSerial
69
70getDeviceSerial(admin: Want): Promise<string>
71
72指定设备管理应用获取设备序列号,使用Promise异步回调。
73
74**需要权限:** ohos.permission.ENTERPRISE_GET_DEVICE_INFO
75
76**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
77
78**参数:**
79
80| 参数名   | 类型                                  | 必填   | 说明      |
81| ----- | ----------------------------------- | ---- | ------- |
82| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
83
84**返回值:**
85
86| 类型                   | 说明                      |
87| --------------------- | ------------------------- |
88| Promise<string> | Promise对象,返回设备序列号。  |
89
90**错误码**:
91
92以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
93
94| 错误码ID | 错误信息                                                                     |
95| ------- | ---------------------------------------------------------------------------- |
96| 9200001 | The application is not an administrator application of the device.            |
97| 9200002 | The administrator application does not have permission to manage the device. |
98| 201 | Permission verification failed. The application does not have the permission required to call the API. |
99| 202 | Permission verification failed. A non-system application calls a system API. |
100| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
101
102**示例:**
103
104```ts
105import { Want } from '@kit.AbilityKit';
106import { BusinessError } from '@kit.BasicServicesKit';
107let wantTemp: Want = {
108  bundleName: 'com.example.myapplication',
109  abilityName: 'EntryAbility',
110};
111
112deviceInfo.getDeviceSerial(wantTemp).then((result) => {
113  console.info(`Succeeded in getting device serial, result : ${result}`);
114}).catch((err: BusinessError) => {
115  console.error(`Failed to get device serial. Code: ${err.code}, message: ${err.message}`);
116});
117```
118
119## deviceInfo.getDisplayVersion
120
121getDisplayVersion(admin: Want, callback: AsyncCallback<string>): void
122
123指定设备管理应用获取设备版本号,使用callback异步回调。
124
125**需要权限:** ohos.permission.ENTERPRISE_GET_DEVICE_INFO
126
127**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
128
129**参数:**
130
131| 参数名      | 类型                                       | 必填   | 说明                       |
132| -------- | ---------------------------------------- | ---- | ------------------------------- |
133| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)      | 是    | 设备管理应用。                  |
134| callback | AsyncCallback<string>            | 是    | 回调函数。当接口调用成功,err为null,data为设备版本号,否则err为错误对象。       |
135
136**错误码**:
137
138以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
139
140| 错误码ID | 错误信息                                                                       |
141| ------- | ---------------------------------------------------------------------------- |
142| 9200001 | The application is not an administrator application of the device.            |
143| 9200002 | The administrator application does not have permission to manage the device. |
144| 201 | Permission verification failed. The application does not have the permission required to call the API. |
145| 202 | Permission verification failed. A non-system application calls a system API. |
146| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
147
148**示例:**
149
150```ts
151import { Want } from '@kit.AbilityKit';
152let wantTemp: Want = {
153  bundleName: 'com.example.myapplication',
154  abilityName: 'EntryAbility',
155};
156
157deviceInfo.getDisplayVersion(wantTemp, (err, result) => {
158  if (err) {
159    console.error(`Failed to get display version. Code: ${err.code}, message: ${err.message}`);
160    return;
161  }
162  console.info(`Succeeded in getting display version, result : ${result}`);
163});
164```
165
166## deviceInfo.getDisplayVersion
167
168getDisplayVersion(admin: Want): Promise<string>
169
170指定设备管理应用获取设备版本号,使用Promise异步回调。
171
172**需要权限:** ohos.permission.ENTERPRISE_GET_DEVICE_INFO
173
174**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
175
176**参数:**
177
178| 参数名   | 类型                                  | 必填   | 说明      |
179| ----- | ----------------------------------- | ---- | ------- |
180| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
181
182**返回值:**
183
184| 类型                   | 说明                      |
185| --------------------- | ------------------------- |
186| Promise<string> | Promise对象,返回设备版本号。 |
187
188**错误码**:
189
190以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
191
192| 错误码ID | 错误信息                                                                     |
193| ------- | ---------------------------------------------------------------------------- |
194| 9200001 | The application is not an administrator application of the device.            |
195| 9200002 | The administrator application does not have permission to manage the device. |
196| 201 | Permission verification failed. The application does not have the permission required to call the API. |
197| 202 | Permission verification failed. A non-system application calls a system API. |
198| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
199
200**示例:**
201
202```ts
203import { Want } from '@kit.AbilityKit';
204import { BusinessError } from '@kit.BasicServicesKit';
205let wantTemp: Want = {
206  bundleName: 'com.example.myapplication',
207  abilityName: 'EntryAbility',
208};
209
210deviceInfo.getDisplayVersion(wantTemp).then((result) => {
211  console.info(`Succeeded in getting display version, result : ${result}`);
212}).catch((err: BusinessError) => {
213  console.error(`Failed to get display version. Code: ${err.code}, message: ${err.message}`);
214});
215```
216
217## deviceInfo.getDeviceName
218
219getDeviceName(admin: Want, callback: AsyncCallback<string>): void
220
221指定设备管理应用获取设备名称,使用callback异步回调。
222
223**需要权限:** ohos.permission.ENTERPRISE_GET_DEVICE_INFO
224
225**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
226
227**参数:**
228
229| 参数名      | 类型                                       | 必填   | 说明                       |
230| -------- | ---------------------------------------- | ---- | ------------------------------- |
231| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)      | 是    | 设备管理应用。                  |
232| callback | AsyncCallback<string>              | 是    | 回调函数。当接口调用成功,err为null,data为设备名称,否则err为错误对象。       |
233
234**错误码**:
235
236以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
237
238| 错误码ID | 错误信息                                                                       |
239| ------- | ---------------------------------------------------------------------------- |
240| 9200001 | The application is not an administrator application of the device.            |
241| 9200002 | The administrator application does not have permission to manage the device. |
242| 201 | Permission verification failed. The application does not have the permission required to call the API. |
243| 202 | Permission verification failed. A non-system application calls a system API. |
244| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
245
246**示例:**
247
248```ts
249import { Want } from '@kit.AbilityKit';
250let wantTemp: Want = {
251  bundleName: 'com.example.myapplication',
252  abilityName: 'EntryAbility',
253};
254
255deviceInfo.getDeviceName(wantTemp, (err, result) => {
256  if (err) {
257    console.error(`Failed to get device name. Code: ${err.code}, message: ${err.message}`);
258    return;
259  }
260  console.info(`Succeeded in getting device name, result : ${result}`);
261});
262```
263
264## deviceInfo.getDeviceName
265
266getDeviceName(admin: Want): Promise<string>
267
268指定设备管理应用获取设备名称,使用Promise异步回调。
269
270**需要权限:** ohos.permission.ENTERPRISE_GET_DEVICE_INFO
271
272**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
273
274**参数:**
275
276| 参数名   | 类型                                  | 必填   | 说明      |
277| ----- | ----------------------------------- | ---- | ------- |
278| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
279
280**返回值:**
281
282| 类型                   | 说明                      |
283| --------------------- | ------------------------- |
284| Promise<string> | Promise结果,返回设备名称。 |
285
286**错误码**:
287
288以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
289
290| 错误码ID | 错误信息                                                                     |
291| ------- | ---------------------------------------------------------------------------- |
292| 9200001 | The application is not an administrator application of the device.            |
293| 9200002 | The administrator application does not have permission to manage the device. |
294| 201 | Permission verification failed. The application does not have the permission required to call the API. |
295| 202 | Permission verification failed. A non-system application calls a system API. |
296| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
297
298**示例:**
299
300```ts
301import { Want } from '@kit.AbilityKit';
302import { BusinessError } from '@kit.BasicServicesKit';
303let wantTemp: Want = {
304  bundleName: 'com.example.myapplication',
305  abilityName: 'EntryAbility',
306};
307
308deviceInfo.getDeviceName(wantTemp).then((result) => {
309  console.info(`Succeeded in getting device name, result : ${result}`);
310}).catch((err: BusinessError) => {
311  console.error(`Failed to get device name. Code: ${err.code}, message: ${err.message}`);
312});
313```