harmony 鸿蒙@system.device (Device Information)

  • 2025-06-12
  • 浏览 (4)

@system.device (Device Information)

The device module provides APIs for checking information about the current device.

NOTE

  • The APIs of this module are no longer maintained since API version 6. It is recommended that you use @ohos.deviceInfo.

  • 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(deprecated)

getInfo(options?: GetDeviceOptions): void

Obtains the device information.

NOTE
Do not call device.getInfo before the onShow event of the home page.

System capability: SystemCapability.Startup.SystemInfo.Lite

Parameters

Name Type Mandatory Description
options GetDeviceOptions No Parameters for obtaining the device information.

GetDeviceOptions(deprecated)

Defines the parameters for obtaining the device information.

System capability: SystemCapability.Startup.SystemInfo.Lite

Name Type Mandatory Description
success (data: DeviceResponse)=> void No Called when an API call is successful. data indicates the returned device information. For details, see DeviceResponse.
fail (data: any,code:number)=> void No Called when an API call has failed. code indicates the error code returned upon a failure.
code:200: Certain information could not be obtained.
complete () => void No Called when an API call is complete.

DeviceResponse(deprecated)

Defines the device information.

System capability: SystemCapability.Startup.SystemInfo.Lite

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: rectangular screen
- circle: round screen
apiVersion4+ number API version.
deviceType4+ string Device type.

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);            
      },        
    });    
  },
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Basic Services Kit

harmony 鸿蒙DeviceInfo

harmony 鸿蒙InitSync

harmony 鸿蒙OH_Print

harmony 鸿蒙OsAccount

harmony 鸿蒙Pasteboard

harmony 鸿蒙Print_Margin

harmony 鸿蒙Print_PageSize

harmony 鸿蒙Print_PrintAttributes

harmony 鸿蒙Print_PrintDocCallback

0  赞