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