1# @system.brightness (屏幕亮度) 2 3<!--Kit: Basic Services Kit--> 4<!--Subsystem: PowerManager--> 5<!--Owner: @zhang-yinglie; @volcano_wang--> 6<!--Designer: @wangyantian0--> 7<!--Tester: @alien0208--> 8<!--Adviser: @w_Machine_cc--> 9 10该模块提供屏幕亮度和模式的查询、调节接口。 11 12> **说明:** 13> 14> - 从API Version 7 开始不再维护<!--Del-->。建议使用[@ohos.brightness](js-apis-brightness-sys.md)替代<!--DelEnd-->,替代接口能力仅对系统应用开放。 15> - 本模块首批接口从API version 3开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 16 17 18## 导入模块 19 20 21```js 22import brightness, { BrightnessModeResponse, BrightnessResponse } from '@system.brightness'; 23``` 24 25 26## brightness.getValue<sup>(deprecated)</sup> 27 28getValue(options?: GetBrightnessOptions): void 29 30获得设备当前的屏幕亮度值。 31 32**系统能力:** SystemCapability.PowerManager.DisplayPowerManager.Lite 33 34**参数:** 35 36| 参数名 | 类型 | 必填 | 说明 | 37| -------- | -------- | -------- | -------- | 38| options | [GetBrightnessOptions](#getbrightnessoptionsdeprecated) | 否 | 获取屏幕亮度的参数对象。可选,默认为空。 | 39 40**示例:** 41 42 ```js 43 brightness.getValue({ 44 success: (data: BrightnessResponse) => { 45 console.log('success get brightness value:' + data.value); 46 }, 47 fail: (data: string, code: number) => { 48 console.error('get brightness fail, code: ' + code + ', data: ' + data); 49 } 50 }); 51 ``` 52 53 54## brightness.setValue<sup>(deprecated)</sup> 55 56setValue(options?: SetBrightnessOptions): void 57 58设置设备当前的屏幕亮度值。 59 60**系统能力:** SystemCapability.PowerManager.DisplayPowerManager.Lite 61 62**参数:** 63 64| 参数名 | 类型 | 必填 | 说明 | 65| -------- | -------- | -------- | -------- | 66| options | [SetBrightnessOptions](#setbrightnessoptionsdeprecated) | 否 | 设置屏幕亮度的参数对象。可选,默认为空。 | 67 68**示例:** 69 70 ```js 71 brightness.setValue({ 72 value: 100, 73 success: () => { 74 console.log('handling set brightness success.'); 75 }, 76 fail: (data: string, code: number) => { 77 console.error('handling set brightness value fail, code:' + code + ', data: ' + data); 78 } 79 }); 80 ``` 81 82 83## brightness.getMode<sup>(deprecated)</sup> 84 85getMode(options?: GetBrightnessModeOptions): void 86 87获得当前屏幕亮度模式。 88 89**系统能力:** SystemCapability.PowerManager.DisplayPowerManager.Lite 90 91**参数:** 92 93| 参数名 | 类型 | 必填 | 说明 | 94| -------- | -------- | -------- | -------- | 95| options | [GetBrightnessModeOptions](#getbrightnessmodeoptionsdeprecated) | 否 | 获取屏幕亮度模式的参数对象。可选,默认为空。 | 96 97**示例:** 98 99 ```js 100 brightness.getMode({ 101 success: (data: BrightnessModeResponse) => { 102 console.log('success get mode:' + data.mode); 103 }, 104 fail: (data: string, code: number) => { 105 console.error('handling get mode fail, code:' + code + ', data: ' + data); 106 } 107 }); 108 ``` 109 110 111## brightness.setMode<sup>(deprecated)</sup> 112 113setMode(options?: SetBrightnessModeOptions): void 114 115设置设备当前的屏幕亮度模式。 116 117**系统能力:** SystemCapability.PowerManager.DisplayPowerManager.Lite 118 119**参数:** 120| 参数名 | 类型 | 必填 | 说明 | 121| -------- | -------- | -------- | -------- | 122| options | [SetBrightnessModeOptions](#setbrightnessmodeoptionsdeprecated) | 否 | 设置屏幕亮度模式的参数对象。可选,默认为空。 | 123 124**示例:** 125 126 ```js 127 brightness.setMode({ 128 mode: 1, 129 success: () => { 130 console.log('handling set mode success.'); 131 }, 132 fail: (data: string, code: number) => { 133 console.error('handling set mode fail, code:' + code + ', data: ' + data); 134 } 135 }); 136 ``` 137 138 139## brightness.setKeepScreenOn<sup>(deprecated)</sup> 140 141setKeepScreenOn(options?: SetKeepScreenOnOptions): void 142 143>从API version 7开始不再维护,建议使用[window.setWindowKeepScreenOn()](../apis-arkui/arkts-apis-window-Window.md#setwindowkeepscreenon9)替代。 144 145设置屏幕是否保持常亮状态,开启常亮模式推荐在onShow()阶段调用。 146 147**系统能力:** SystemCapability.PowerManager.DisplayPowerManager.Lite 148 149**参数:** 150 151| 参数名 | 类型 | 必填 | 说明 | 152| -------- | -------- | -------- | -------- | 153| options | [SetKeepScreenOnOptions](#setkeepscreenonoptionsdeprecated) | 否 | 设置屏幕常亮的参数对象。可选,默认为空。 | 154 155**示例:** 156 157 ```js 158 brightness.setKeepScreenOn({ 159 keepScreenOn: true, 160 success: () => { 161 console.log('handling set keep screen on success.'); 162 }, 163 fail: (data: string, code: number) => { 164 console.error('handling set keep screen on fail, code:' + code + ', data: ' + data); 165 } 166 }); 167 ``` 168## GetBrightnessOptions<sup>(deprecated)</sup> 169 170获取屏幕亮度的参数对象。 171 172**系统能力:** SystemCapability.PowerManager.DisplayPowerManager.Lite 173 174| 名称 | 类型 | 必填 | 说明 | 175| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | 176| success | (data: [BrightnessResponse](#brightnessresponsedeprecated)) => void | 否 | 接口调用成功的回调函数。data为[BrightnessResponse](#brightnessresponsedeprecated)类型的返回值。 | 177| fail | (data: string, code: number) => void | 否 | 接口调用失败的回调函数。data为错误信息,code为错误码。 | 178| complete | () => void | 否 | 接口调用结束的回调函数。 | 179 180## SetBrightnessOptions<sup>(deprecated)</sup> 181 182设置屏幕亮度的参数对象。 183 184**系统能力:** SystemCapability.PowerManager.DisplayPowerManager.Lite 185 186| 名称 | 类型 | 必填 | 说明 | 187| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 188| value | number | 是 | 屏幕亮度,值为1-255之间的整数。<br/>- 如果值小于等于0,系统按1处理。<br/>- 如果值大于255,系统按255处理。<br/>- 如果值为小数,系统将处理为整数。例如设置为8.1,系统按8处理。 | 189| success | () => void | 否 | 接口调用成功的回调函数。 | 190| fail | (data: string, code: number) => void | 否 | 接口调用失败的回调函数。data为错误信息,code为错误码。 | 191| complete | () => void | 否 | 接口调用结束的回调函数。 | 192 193## BrightnessResponse<sup>(deprecated)</sup> 194 195包含屏幕亮度的对象。 196 197**系统能力:** SystemCapability.PowerManager.DisplayPowerManager.Lite 198 199| 名称 | 类型 | 可读 | 可写 | 说明 | 200| -------- | -------- | -------- | -------- | -------- | 201| value | number | 是 | 否 | 屏幕亮度,范围:1到255。 | 202 203## GetBrightnessModeOptions<sup>(deprecated)</sup> 204 205获取屏幕亮度模式的参数对象。 206 207**系统能力:** SystemCapability.PowerManager.DisplayPowerManager.Lite 208 209| 名称 | 类型 | 必填 | 说明 | 210| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 211| success | (data: [BrightnessModeResponse](#brightnessmoderesponsedeprecated)) => void | 否 | 接口调用成功的回调函数。data为[BrightnessModeResponse](#brightnessmoderesponsedeprecated)类型的返回值。 | 212| fail | (data: string, code: number) => void | 否 | 接口调用失败的回调函数。data为错误信息,code为错误码。 | 213| complete | () => void | 否 | 接口调用结束的回调函数。 | 214 215## SetBrightnessModeOptions<sup>(deprecated)</sup> 216 217设置屏幕亮度模式的参数对象。 218 219**系统能力:** SystemCapability.PowerManager.DisplayPowerManager.Lite 220 221| 名称 | 类型 | 必填 | 说明 | 222| -------- | ------------------------------------ | ---- | ------------------------------------------------------ | 223| mode | number | 是 | 0表示手动调节屏幕亮度模式,1表示自动调节屏幕亮度模式。 | 224| success | () => void | 否 | 接口调用成功的回调函数。 | 225| fail | (data: string, code: number) => void | 否 | 接口调用失败的回调函数。data为错误信息,code为错误码。 | 226| complete | () => void | 否 | 接口调用结束的回调函数。 | 227 228## BrightnessModeResponse<sup>(deprecated)</sup> 229 230包含屏幕亮度模式的对象。 231 232**系统能力:** SystemCapability.PowerManager.DisplayPowerManager.Lite 233 234| 名称 | 类型 | 可读 | 可写 | 说明 | 235| -------- | -------- | -------- | -------- | -------- | 236| mode | number | 是 | 否 | 0表示手动调节屏幕亮度模式,1表示自动调节屏幕亮度模式。 | 237 238## SetKeepScreenOnOptions<sup>(deprecated)</sup> 239 240设置屏幕常亮的参数对象。 241 242**系统能力:** SystemCapability.PowerManager.DisplayPowerManager.Lite 243 244| 名称 | 类型 | 必填 | 说明 | 245| ------------ | ------------------------------------ | ---- | ------------------------------------------------------ | 246| keepScreenOn | boolean | 是 | true表示保持屏幕常亮,false表示取消屏幕常亮。 | 247| success | () => void | 否 | 接口调用成功的回调函数。 | 248| fail | (data: string, code: number) => void | 否 | 接口调用失败的回调函数。data为错误信息,code为错误码。 | 249| complete | () => void | 否 | 接口调用结束的回调函数。 | 250 251