openharmony 鸿蒙 js-apis-system-brightness

2025-06-12 浏览 (1)

@system.brightness (屏幕亮度)

该模块提供屏幕亮度和模式的查询、调节接口。

说明:

  • 从API Version 7 开始不再维护。建议使用@ohos.brightness替代,替代接口能力仅对系统应用开放。
  • 本模块首批接口从API version 3开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

import brightness, { BrightnessModeResponse, BrightnessResponse } from '@system.brightness';

brightness.getValue(deprecated)

getValue(options?: GetBrightnessOptions): void

获得设备当前的屏幕亮度值。

系统能力: SystemCapability.PowerManager.DisplayPowerManager.Lite

参数:

参数名类型必填说明
optionsGetBrightnessOptions获取屏幕亮度的参数对象。可选,默认为空。

示例:

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

设置设备当前的屏幕亮度值。

系统能力: SystemCapability.PowerManager.DisplayPowerManager.Lite

参数:

参数名类型必填说明
optionsSetBrightnessOptions设置屏幕亮度的参数对象。可选,默认为空。

示例:

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

获得当前屏幕亮度模式。

系统能力: SystemCapability.PowerManager.DisplayPowerManager.Lite

参数:

参数名类型必填说明
optionsGetBrightnessModeOptions获取屏幕亮度模式的参数对象。可选,默认为空。

示例:

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

设置设备当前的屏幕亮度模式。

系统能力: SystemCapability.PowerManager.DisplayPowerManager.Lite

参数:

参数名类型必填说明
optionsSetBrightnessModeOptions设置屏幕亮度模式的参数对象。可选,默认为空。

示例:

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

从API version 7开始不再维护,建议使用window.setWindowKeepScreenOn()替代。

设置屏幕是否保持常亮状态,开启常亮模式推荐在onShow()阶段调用。

系统能力: SystemCapability.PowerManager.DisplayPowerManager.Lite

参数:

参数名类型必填说明
optionsSetKeepScreenOnOptions设置屏幕常亮的参数对象。可选,默认为空。

示例:

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)

获取屏幕亮度的参数对象。

系统能力: SystemCapability.PowerManager.DisplayPowerManager.Lite

名称类型必填说明
success(data: BrightnessResponse) => void接口调用成功的回调函数。data为BrightnessResponse类型的返回值。
fail(data: string, code: number) => void接口调用失败的回调函数。data为错误信息,code为错误码。
complete() => void接口调用结束的回调函数。

SetBrightnessOptions(deprecated)

设置屏幕亮度的参数对象。

系统能力: SystemCapability.PowerManager.DisplayPowerManager.Lite

名称类型必填说明
valuenumber屏幕亮度,值为1-255之间的整数。
- 如果值小于等于0,系统按1处理。
- 如果值大于255,系统按255处理。
- 如果值为小数,系统将处理为整数。例如设置为8.1,系统按8处理。
success() => void接口调用成功的回调函数。
fail(data: string, code: number) => void接口调用失败的回调函数。data为错误信息,code为错误码。
complete() => void接口调用结束的回调函数。

BrightnessResponse(deprecated)

包含屏幕亮度的对象。

系统能力: SystemCapability.PowerManager.DisplayPowerManager.Lite

名称类型可读可写说明
valuenumber屏幕亮度,范围:1到255。

GetBrightnessModeOptions(deprecated)

获取屏幕亮度模式的参数对象。

系统能力: SystemCapability.PowerManager.DisplayPowerManager.Lite

名称类型必填说明
success(data: BrightnessModeResponse) => void接口调用成功的回调函数。data为BrightnessModeResponse类型的返回值。
fail(data: string, code: number) => void接口调用失败的回调函数。data为错误信息,code为错误码。
complete() => void接口调用结束的回调函数。

SetBrightnessModeOptions(deprecated)

设置屏幕亮度模式的参数对象。

系统能力: SystemCapability.PowerManager.DisplayPowerManager.Lite

名称类型必填说明
modenumber0表示手动调节屏幕亮度模式,1表示自动调节屏幕亮度模式。
success() => void接口调用成功的回调函数。
fail(data: string, code: number) => void接口调用失败的回调函数。data为错误信息,code为错误码。
complete() => void接口调用结束的回调函数。

BrightnessModeResponse(deprecated)

包含屏幕亮度模式的对象。

系统能力: SystemCapability.PowerManager.DisplayPowerManager.Lite

名称类型可读可写说明
modenumber0表示手动调节屏幕亮度模式,1表示自动调节屏幕亮度模式。

SetKeepScreenOnOptions(deprecated)

设置屏幕常亮的参数对象。

系统能力: SystemCapability.PowerManager.DisplayPowerManager.Lite

名称类型必填说明
keepScreenOnbooleantrue表示保持屏幕常亮,false表示取消屏幕常亮。
success() => void接口调用成功的回调函数。
fail(data: string, code: number) => void接口调用失败的回调函数。data为错误信息,code为错误码。
complete() => void接口调用结束的回调函数。

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Basic Services Kit(基础服务)

harmony 鸿蒙DeviceInfo

harmony 鸿蒙OH_Print

harmony 鸿蒙Print_Margin

harmony 鸿蒙Print_PageSize

harmony 鸿蒙Print_PrintAttributes

harmony 鸿蒙Print_PrintDocCallback

harmony 鸿蒙Print_Range

harmony 鸿蒙TimeService

harmony 鸿蒙ohscan.h

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