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