openharmony 鸿蒙 js-apis-system-brightness

2025-06-12 浏览 (1)

@system.brightness (Screen Brightness)

The brightness module provides APIs for querying and adjusting the screen brightness and mode.

NOTE

  • The APIs of this module are no longer maintained since API version 7. You are advised to use APIs of @ohos.brightness. The substitute APIs are available only for system applications.
  • 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 brightness, { BrightnessModeResponse, BrightnessResponse } from '@system.brightness';

brightness.getValue(deprecated)

getValue(options?: GetBrightnessOptions): void

Obtains the current screen brightness.

System capability: SystemCapability.PowerManager.DisplayPowerManager.Lite

Parameters

NameTypeMandatoryDescription
optionsGetBrightnessOptionsNoOptions for obtaining the screen brightness. This parameter is optional and is left blank by default.

Example

brightness.getValue({
    success: (data: BrightnessResponse) => {
      console.log('success get brightness value:' + data.value);
    },
    fail: (data: string, code: number) => {
      console.error('get brightness fail, code: ' + code + ', data: ' + data);
    }
});

brightness.setValue(deprecated)

setValue(options?: SetBrightnessOptions): void

Sets the screen brightness.

System capability: SystemCapability.PowerManager.DisplayPowerManager.Lite

Parameters

NameTypeMandatoryDescription
optionsSetBrightnessOptionsNoOptions for setting the screen brightness. This parameter is optional and is left blank by default.

Example

brightness.setValue({
    value: 100,
    success: () => {
      console.log('handling set brightness success.');
    },
    fail: (data: string, code: number) => {
      console.error('handling set brightness value fail, code:' + code + ', data: ' + data);
    }
});

brightness.getMode(deprecated)

getMode(options?: GetBrightnessModeOptions): void

Obtains the screen brightness adjustment mode.

System capability: SystemCapability.PowerManager.DisplayPowerManager.Lite

Parameters

NameTypeMandatoryDescription
optionsGetBrightnessModeOptionsNoOptions for obtaining the screen brightness mode. This parameter is optional and is left blank by default.

Example

brightness.getMode({
    success: (data: BrightnessModeResponse) => {
      console.log('success get mode:' + data.mode);
    },
    fail: (data: string, code: number) => {
      console.error('handling get mode fail, code:' + code + ', data: ' + data);
    }
});

brightness.setMode(deprecated)

setMode(options?: SetBrightnessModeOptions): void

Sets the screen brightness adjustment mode.

System capability: SystemCapability.PowerManager.DisplayPowerManager.Lite

Parameters

NameTypeMandatoryDescription
optionsSetBrightnessModeOptionsNoOptions for setting the screen brightness mode. This parameter is optional and is left blank by default.

Example

brightness.setMode({
    mode: 1,
    success: () => {
      console.log('handling set mode success.');
    },
    fail: (data: string, code: number) => {
      console.error('handling set mode fail, code:' + code + ', data: ' + data);
    }
});

brightness.setKeepScreenOn(deprecated)

setKeepScreenOn(options?: SetKeepScreenOnOptions): void

This API is no longer maintained since API version 7. You are advised to use window.setWindowKeepScreenOn().

Sets whether to always keep the screen on. Call this API in onShow().

System capability: SystemCapability.PowerManager.DisplayPowerManager.Lite

Parameters

NameTypeMandatoryDescription
optionsSetKeepScreenOnOptionsNoOptions for setting the screen to be steady on. This parameter is optional and is left blank by default.

Example

brightness.setKeepScreenOn({
    keepScreenOn: true,
    success: () => {
      console.log('handling set keep screen on success.');
    },
    fail: (data: string, code: number) => {
      console.error('handling set keep screen on fail, code:' + code + ', data: ' + data);
    }
});

GetBrightnessOptions(deprecated)

Options for obtaining the screen brightness.

System capability: SystemCapability.PowerManager.DisplayPowerManager.Lite

NameTypeMandatoryDescription
success(data: BrightnessResponse) => voidNoCalled when an API call is successful. data is a return value of the BrightnessResponse type.
fail(data: string, code: number) => voidNoCalled when an API call has failed. data indicates the error information, and code indicates the error code.
complete() => voidNoCalled when an API call is complete.

SetBrightnessOptions(deprecated)

Options for setting the screen brightness.

System capability: SystemCapability.PowerManager.DisplayPowerManager.Lite

NameTypeMandatoryDescription
valuenumberYesScreen brightness. The value is an integer ranging from 1 to 255.
- If the value is less than or equal to 0, value 1 will be used.
- If the value is greater than 255, value 255 will be used.
- If the value contains decimals, the integral part of the value will be used. For example, if value 8.1 is set, value 8 will be used.
success() => voidNoCalled when API call is successful.
fail(data: string, code: number) => voidNoCalled when an API call has failed. data indicates the error information, and code indicates the error code.
complete() => voidNoCalled when an API call is complete.

BrightnessResponse(deprecated)

Defines a response that returns the screen brightness.

System capability: SystemCapability.PowerManager.DisplayPowerManager.Lite

NameTypeReadableWritableDescription
valuenumberYesNoScreen brightness. The value ranges from 1 to 255.

GetBrightnessModeOptions(deprecated)

Defines the options for obtaining the screen brightness mode.

System capability: SystemCapability.PowerManager.DisplayPowerManager.Lite

NameTypeMandatoryDescription
success(data: BrightnessModeResponse) => voidNoCalled when an API call is successful. data is a return value of the BrightnessModeResponse type.
fail(data: string, code: number) => voidNoCalled when an API call has failed. data indicates the error information, and code indicates the error code.
complete() => voidNoCalled when an API call is complete.

SetBrightnessModeOptions(deprecated)

Options for setting the screen brightness mode.

System capability: SystemCapability.PowerManager.DisplayPowerManager.Lite

NameTypeMandatoryDescription
modenumberYesThe value 0 indicates the manual adjustment mode, and the value 1 indicates the automatic adjustment mode.
success() => voidNoCalled when API call is successful.
fail(data: string, code: number) => voidNoCalled when an API call has failed. data indicates the error information, and code indicates the error code.
complete() => voidNoCalled when an API call is complete.

BrightnessModeResponse(deprecated)

Defines a response that returns the screen brightness mode.

System capability: SystemCapability.PowerManager.DisplayPowerManager.Lite

NameTypeReadableWritableDescription
modenumberYesNoThe value 0 indicates the manual adjustment mode, and the value 1 indicates the automatic adjustment mode.

SetKeepScreenOnOptions(deprecated)

Options for setting the screen to be steady on.

System capability: SystemCapability.PowerManager.DisplayPowerManager.Lite

NameTypeMandatoryDescription
keepScreenOnbooleanYesThe value true means to keep the screen steady on, and the value false indicates the opposite.
success() => voidNoCalled when API call is successful.
fail(data: string, code: number) => voidNoCalled when an API call has failed. data indicates the error information, and code indicates the error code.
complete() => voidNoCalled when an API call is complete.

你可能感兴趣的鸿蒙文章

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/0fPa3K