js-apis-system-device.md 2.9 KB
Newer Older
E
ester.zhou 已提交
1
# @system.device (Device Information)
Z
zengyawen 已提交
2

E
esterzhou 已提交
3 4 5
The **device** module provides APIs for checking information about the current device.

> **NOTE**
E
ester.zhou 已提交
6
>
E
esterzhou 已提交
7
> - The APIs of this module are no longer maintained since API version 6. It is recommended that you use [@ohos.deviceInfo](js-apis-device-info.md) instead.
E
ester.zhou 已提交
8
>
Z
zengyawen 已提交
9 10 11 12
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.

## Modules to Import

E
ester.zhou 已提交
13
```typescript
Z
zengyawen 已提交
14 15 16 17 18 19 20 21 22
import device from '@system.device';
```

## device.getInfo

getInfo(Object): void

Obtains the device information.

E
esterzhou 已提交
23 24
> **NOTE**
>
Z
zengyawen 已提交
25 26
> Do not call **device.getInfo** before the **onShow** event of the home page.

E
esterzhou 已提交
27
**System capability**: SystemCapability.Startup.SystemInfo
Z
zengyawen 已提交
28 29 30

**Parameters**

E
esterzhou 已提交
31
| Name| Type| Mandatory| Description|
Z
zengyawen 已提交
32
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
33 34 35
| success | Function | No| Called when API call is successful.|
| fail | Function | No| Called when API call has failed.|
| complete | Function | No| Called when API call is complete.|
Z
zengyawen 已提交
36

E
esterzhou 已提交
37
**Return value of success()**
Z
zengyawen 已提交
38

E
esterzhou 已提交
39
| Name| Type| Description|
Z
zengyawen 已提交
40
| -------- | -------- | -------- |
E
esterzhou 已提交
41 42
| brand | string | Brand.|
| manufacturer | string | Manufacturer.|
E
ester.zhou 已提交
43
| model | string | Model.|
E
esterzhou 已提交
44 45 46 47 48 49
| product | string | Product number.|
| language<sup>4+</sup> | string | System language.|
| region<sup>4+</sup> | string | System region.|
| windowWidth | number | Window width.|
| windowHeight | number | Window height.|
| screenDensity<sup>4+</sup> | number | Screen density.|
E
ester.zhou 已提交
50
| screenShape<sup>4+</sup> | string | Screen shape. The options are as follows:<br>- **rect**: rectangular screen<br>- **circle**: round screen|
E
esterzhou 已提交
51 52 53 54 55 56 57
| apiVersion<sup>4+</sup> | number | API version.|
| releaseType<sup>4+</sup> | string | Release type. The value includes both the release type and the API version, for example, Beta1.<br>Available release types are as follows:<br>- **Canary**: For the same API version, different canary releases are compatible with each other, but not compatible with those of the **beta** and **release** type.<br>- **Beta**: For the same API version, different beta releases are compatible with each other, but not compatible with those of the **release** type.<br>- **Release**: Releases of this type are compatible with the latest five API versions.|
| deviceType<sup>4+</sup> | string | Device type.|

**Return value of fail()**

| Error Code| Description|
Z
zengyawen 已提交
58
| -------- | -------- |
E
ester.zhou 已提交
59
| 200 | Certain information cannot be obtained.|
Z
zengyawen 已提交
60 61 62

**Example**

E
ester.zhou 已提交
63
```typescript
Z
zengyawen 已提交
64 65 66 67 68 69 70 71 72 73 74 75
export default {    
  getInfo() {        
    device.getInfo({            
      success: function(data) {                
        console.log('Device information obtained successfully. Device brand:' + data.brand);            
      },            
      fail: function(data, code) {                
        console.log('Failed to obtain device information. Error code:'+ code + '; Error information: ' + data);            
      },        
    });    
  },
}
E
esterzhou 已提交
76
```