目录

System Information

has.env

has.env: Object

Environment variable.

Since: 1.0.0

Supported attributes

Name Type Mandatory Description
USER_DATA_PATH string No User directory path (local path) in the file system.

Example:

const path = has.env.USER_DATA_PATH;

has.getSystemInfoSync

has.getSystemInfoSync(): Object

Obtains system information in synchronous mode.

Since: 1.0.0

Returns

An object containing the following system information fields.

Parameter Type Description
brand string Mobile phone brand.
model string Mobile phone model.
screenWidth number Screen width of the mobile phone, in px.
screenHeight number Screen height of the mobile phone, in px.
windowWidth number Available window width of the mobile phone, in px.
windowHeight number Available window height of the mobile phone, in px.
statusBarHeight number Height of the mobile phone status bar, in px.
safeArea Object

Safe area on the portrait screen. Some device models do not have the concept of safe area and will not return the safeArea field. You need to address compatibility issues.

Since: 1.0.10

language string Language of the mobile phone system, for example, en_US.
SDKVersion string ASCF version number, which is a three-digit number in the format of [major].[minor].[revision], for example, 1.0.0.
OSApiVersion string System API version. For example, the value is 12 in HarmonyOS 5.0.
system string

System version.

Since: 1.0.3

platform string

Client platform. The value is fixed at 'ohos'.

Since: 1.0.9

fontSizeSetting number User-defined font size, in px.
bluetoothEnabled boolean

System switch for enabling or disabling Bluetooth on the mobile phone.

- true: enabled.

- false: disabled.

locationEnabled boolean

System switch for enabling or disabling location services on the mobile phone.

- true: enabled.

- false: disabled.

wifiEnabled boolean

System switch for enabling or disabling Wi-Fi on the mobile phone.

- true: enabled.

- false: disabled.

deviceOrientation string

Device orientation.

Valid values:

- portrait

- landscape

theme string System theme, which can be set to `light` or `dark`.
indicatorHeight number

Height of the bottom navigation bar, in px. It can be used to calculate the avoidance height on an immersive page.

Since: 1.0.3

Example:

const sysInfo = has.getSystemInfoSync();
console.info(sysInfo.brand);
console.info(sysInfo.windowWidth);
console.info(sysInfo.windowHeight);
console.info(sysInfo.statusBarHeight);

has.getSystemInfo

has.getSystemInfo(Object object)

Obtains system information in asynchronous mode.

Since: 1.0.0

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
success function No

Callback triggered when the API call is successful.

The callback itself does not return any value. For details about the callback parameters of success and complete when the API call is successful, see "Return value of has.getSystemInfoSync".

fail function No

Callback triggered when the API call fails.

In the case of callback failure, the callback parameters of fail and complete contain only the errMsg field.

complete function No Callback triggered when the API call is complete, regardless of success or failure.

Error code information

Error Code Error Message
10000101 Get system info error.

Example:

has.getSystemInfo({
  success: (res) => {
    console.info(res.brand);
    console.info(res.windowWidth);
    console.info(res.windowHeight);
    console.info(res.statusBarHeight);
  },
  fail: (err) => {
    console.error('get system info fail', err);
  },
  complete: (res) => {
    console.info('get system info complete', res);
  }
});

has.getWindowInfo

has.getWindowInfo(): Object

Obtains window information in synchronous mode.

Since: 1.0.12

Returns

An object containing the following window information fields.

Parameter Type Description
pixelRatio number Device pixel ratio.
screenWidth number Screen width of the mobile phone, in px.
screenHeight number Screen height of the mobile phone, in px.
windowWidth number Available window width, in px.
windowHeight number Available window height, in px.
statusBarHeight number Height of the status bar, in px.
safeArea Object Safe area on the portrait screen, including the bottom navigation bar. Some device models do not have the concept of safe area and will not return the safeArea field. You need to address compatibility issues.
screenTop number Y value of the window's top edge, in px.
indicatorHeight number

Height of the bottom navigation bar, in px. It can be used to calculate the avoidance height on an immersive page.

Since: 1.0.23

Example:

const windowInfo = has.getWindowInfo();
console.info(windowInfo.pixelRatio);
console.info(windowInfo.screenWidth);
console.info(windowInfo.screenHeight);
console.info(windowInfo.windowWidth);
console.info(windowInfo.windowHeight);
console.info(windowInfo.statusBarHeight);
console.info(windowInfo.safeArea);
console.info(windowInfo.screenTop);
console.info(windowInfo.indicatorHeight);

safeArea

Safe area on the portrait screen. Some device models do not have the concept of safe area and will not return the safeArea field. You need to address compatibility issues.

In versions earlier than ASCF 2.0.1, the safe area includes the bottom navigation bar. If you need to calculate the height for avoiding the bottom navigation bar, you can use the indicatorHeight field. In versions later than ASCF 2.0.1, the safe area does not include the bottom navigation bar.

Parameter Type Description
left number Horizontal coordinate of the upper left corner of the safe area.
right number Horizontal coordinate of the lower right corner of the safe area.
top number Vertical coordinate of the upper left corner of the safe area.
bottom number Vertical coordinate of the lower right corner of the safe area.
width number Width of the safe area, in logical pixels.
height number Height of the safe area, in logical pixels.

has.getSystemSetting

has.getSystemSetting(): Object

Obtains system settings in synchronous mode.

Since: 1.0.12

Returns

An object containing the following system settings fields.

Parameter Type Description
bluetoothEnabled boolean

Whether to enable Bluetooth.

- true: enabled.

- false: disabled.

locationEnabled boolean

Whether to enable the location service.

- true: enabled.

- false: disabled.

wifiEnabled boolean

Whether to enable Wi-Fi.

- true: enabled.

- false: disabled.

deviceOrientation string

Device orientation.

Valid values:

- portrait

- landscape

Example:

const systemSetting = has.getSystemSetting();
console.info(systemSetting.bluetoothEnabled);
console.info(systemSetting.deviceOrientation);
console.info(systemSetting.locationEnabled);
console.info(systemSetting.wifiEnabled);

has.getDeviceInfo

has.getDeviceInfo(): Object

Obtains device information in synchronous mode.

Since: 1.0.12

Returns

An object containing the following device information fields.

Parameter Type Description
brand string Device brand.
model string Device model.
system string OS and its version.
platform string Client platform.
memorySize string Device memory size, in MB.

Example:

const deviceInfo = has.getDeviceInfo();

console.info(deviceInfo.brand);
console.info(deviceInfo.model);
console.info(deviceInfo.platform);
console.info(deviceInfo.system);