openharmony 鸿蒙 js-apis-brightness-sys

2025-06-12 浏览 (1)

@ohos.brightness (Screen Brightness) (System API)

The brightness module provides an API for setting the screen brightness.

NOTE

  • The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.

  • The APIs provided by this module are system APIs.

Modules to Import

import brightness from '@ohos.brightness';

brightness.setValue

setValue(value: number): void

Sets the screen brightness.

System API: This is a system API.

System capability: SystemCapability.PowerManager.DisplayPowerManager

Parameters

NameTypeMandatoryDescription
valuenumberYesBrightness value. Value range: 0 to 255. The value of this parameter must be a number.

Error codes

For details about the error codes, see Screen Brightness Error Codes.

IDError Message
4700101Failed to connect to the service.
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.
202Permission verification failed. A non-system application calls a system API.

Example:

try {
    brightness.setValue(128);
} catch(err) {
    console.error('set brightness failed, err: ' + err);
}

brightness.setValue11+

setValue(value: number, continuous: boolean): void

Sets the screen brightness. This API is used for continuous brightness adjustment. To achieve a better performance, set continuous to true when you start, and set it to false after you finish.

System API: This is a system API.

System capability: SystemCapability.PowerManager.DisplayPowerManager

Parameters

NameTypeMandatoryDescription
valuenumberYesBrightness value. Value range: 0 to 255. The value of this parameter must be a number.
continuousbooleanYesWhether the luminance adjustment is continuous. The value of this parameter must be of the Boolean type.

Error codes

For details about the error codes, see Screen Brightness Error Codes.

IDError Message
4700101Failed to connect to the service.
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.
202Permission verification failed. A non-system application calls a system API.

Example:

try {
    brightness.setValue(128, true);
} catch(err) {
    console.error('set brightness failed, err: ' + err);
}

你可能感兴趣的鸿蒙文章

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

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