harmony 鸿蒙@system.device (Device Information)

2022-08-09 浏览 (957)

@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 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(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

NameTypeMandatoryDescription
optionsGetDeviceOptionsNoParameters for obtaining the device information.

GetDeviceOptions

Defines the parameters for obtaining the device information.

System capability: SystemCapability.Startup.SystemInfo.Lite

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

DeviceResponse

Provides the device information.

System capability: SystemCapability.Startup.SystemInfo.Lite

NameTypeDescription
brandstringBrand.
manufacturerstringManufacturer.
modelstringModel.
productstringProduct number.
language4+stringSystem language.
region4+stringSystem region.
windowWidthnumberWindow width.
windowHeightnumberWindow height.
screenDensity4+numberScreen density.
screenShape4+stringScreen shape. The options are as follows:
- rect: rectangular screen
- circle: round screen
apiVersion4+numberAPI version.
deviceType4+stringDevice 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 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/de797d4466a7418fb9cccddf646a4a4e