Device Information
NOTE
The APIs of this module are no longer maintained since API version 6. It is recommended that you use
@ohos.deviceInfo
instead.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
import device from '@system.device';
device.getInfo
getInfo(Object): void
Obtains the device information.
Note: Do not call device.getInfo before the onShow event of the home page.
System capability: SystemCapability.Startup.SysInfo
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
success | Function | No | Called when the device information is obtained |
fail | Function | No | Called when the device information fails to be obtained |
complete | Function | No | Called when the execution is complete |
The following values will be returned when the device information is obtained.
Name | Type | Description |
---|---|---|
brand | string | Brand |
manufacturer | string | Manufacturer |
model | string | Model |
product | string | Product number |
language4+ | string | System language |
region4+ | string | System region |
windowWidth | number | Window width |
windowHeight | number | Window height |
screenDensity4+ | number | Screen density |
screenShape4+ | string | Screen shape. The options are as follows: - rect: rectangle screen - circle: circle screen |
apiVersion4+ | number | API version |
releaseType4+ | string | Release type. The value includes both the release type and the API version, for example, Beta1. Available release types are as follows: - 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. - Beta: For the same API version, different beta releases are compatible with each other, but not compatible with those of the release type. - Release: Releases of this type are compatible with the latest five API versions. |
deviceType4+ | string | Device type |
The following error code will be returned if the device information fails to be obtained.
Error Code | Description |
---|---|
200 | The returned result contains information that cannot be obtained. |
Example
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);
},
});
},
}