1# @ohos.enterprise.deviceInfo (Device Information Management) 2 3The **deviceInfo** module provides APIs for enterprise device information management, including the API for obtaining device serial numbers. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> - The APIs of this module can be used only in the stage model. 10> 11> - The APIs provided by this module can be called only by a [device administrator application](enterpriseDeviceManagement-overview.md#basic-concepts) that is [enabled](js-apis-enterprise-adminManager.md#adminmanagerenableadmin). 12 13## Modules to Import 14 15```ts 16import deviceInfo from '@ohos.enterprise.deviceInfo'; 17``` 18 19## deviceInfo.getDeviceSerial 20 21getDeviceSerial(admin: Want, callback: AsyncCallback<string>): void 22 23Obtains the device serial number through the specified device administrator application. This API uses an asynchronous callback to return the result. 24 25**Required permissions**: ohos.permission.ENTERPRISE_GET_DEVICE_INFO 26 27**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 28 29**System API**: This is a system API. 30 31**Parameters** 32 33| Name | Type | Mandatory | Description | 34| -------- | ---------------------------------------- | ---- | ------------------------------- | 35| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 36| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the device serial number obtained. If the operation fails, **err** is an error object. | 37 38**Error codes** 39 40For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 41 42| ID| Error Message | 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**Example** 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 69Obtains the device serial number through the specified device administrator application. This API uses a promise to return the result. 70 71**Required permissions**: ohos.permission.ENTERPRISE_GET_DEVICE_INFO 72 73**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 74 75**System API**: This is a system API. 76 77**Parameters** 78 79| Name | Type | Mandatory | Description | 80| ----- | ----------------------------------- | ---- | ------- | 81| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 82 83**Return value** 84 85| Type | Description | 86| --------------------- | ------------------------- | 87| Promise<string> | Promise used to return the device serial number. | 88 89**Error codes** 90 91For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 92 93| ID| Error Message | 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**Example** 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 119Obtains the device version through the specified device administrator application. This API uses an asynchronous callback to return the result. 120 121**Required permissions**: ohos.permission.ENTERPRISE_GET_DEVICE_INFO 122 123**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 124 125**System API**: This is a system API. 126 127**Parameters** 128 129| Name | Type | Mandatory | Description | 130| -------- | ---------------------------------------- | ---- | ------------------------------- | 131| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 132| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the device version obtained. If the operation fails, **err** is an error object. | 133 134**Error codes** 135 136For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 137 138| ID| Error Message | 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**Example** 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 165Obtains the device version through the specified device administrator application. This API uses a promise to return the result. 166 167**Required permissions**: ohos.permission.ENTERPRISE_GET_DEVICE_INFO 168 169**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 170 171**System API**: This is a system API. 172 173**Parameters** 174 175| Name | Type | Mandatory | Description | 176| ----- | ----------------------------------- | ---- | ------- | 177| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 178 179**Return value** 180 181| Type | Description | 182| --------------------- | ------------------------- | 183| Promise<string> | Promise used to return the device version obtained.| 184 185**Error codes** 186 187For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 188 189| ID| Error Message | 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**Example** 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 215Obtains the device name through the specified device administrator application. This API uses an asynchronous callback to return the result. 216 217**Required permissions**: ohos.permission.ENTERPRISE_GET_DEVICE_INFO 218 219**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 220 221**System API**: This is a system API. 222 223**Parameters** 224 225| Name | Type | Mandatory | Description | 226| -------- | ---------------------------------------- | ---- | ------------------------------- | 227| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 228| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the device name obtained. If the operation fails, **err** is an error object. | 229 230**Error codes** 231 232For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 233 234| ID| Error Message | 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**Example** 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 261Obtains the device name through the specified device administrator application. This API uses a promise to return the result. 262 263**Required permissions**: ohos.permission.ENTERPRISE_GET_DEVICE_INFO 264 265**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 266 267**System API**: This is a system API. 268 269**Parameters** 270 271| Name | Type | Mandatory | Description | 272| ----- | ----------------------------------- | ---- | ------- | 273| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 274 275**Return value** 276 277| Type | Description | 278| --------------------- | ------------------------- | 279| Promise<string> | Promise used to return the device name.| 280 281**Error codes** 282 283For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 284 285| ID| Error Message | 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**Example** 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``` 306