1# @system.brightness (Screen 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 10The **brightness** module provides APIs for querying and adjusting the screen brightness and mode. 11 12> **NOTE** 13> 14> - The APIs of this module are no longer maintained since API version 7.<!--Del--> You are advised to use APIs of [@ohos.brightness](js-apis-brightness-sys.md). <!--DelEnd-->The substitute APIs are available only for system applications. 15> - 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. 16 17 18## Modules to Import 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 30Obtains the current screen brightness. 31 32**System capability**: SystemCapability.PowerManager.DisplayPowerManager.Lite 33 34**Parameters** 35 36| Name| Type| Mandatory| Description| 37| -------- | -------- | -------- | -------- | 38| options | [GetBrightnessOptions](#getbrightnessoptionsdeprecated) | No | Options for obtaining the screen brightness. This parameter is optional and is left blank by default.| 39 40**Example** 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 58Sets the screen brightness. 59 60**System capability**: SystemCapability.PowerManager.DisplayPowerManager.Lite 61 62**Parameters** 63 64| Name| Type| Mandatory| Description| 65| -------- | -------- | -------- | -------- | 66| options | [SetBrightnessOptions](#setbrightnessoptionsdeprecated) | No | Options for setting the screen brightness. This parameter is optional and is left blank by default.| 67 68**Example** 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 87Obtains the screen brightness adjustment mode. 88 89**System capability**: SystemCapability.PowerManager.DisplayPowerManager.Lite 90 91**Parameters** 92 93| Name| Type| Mandatory| Description| 94| -------- | -------- | -------- | -------- | 95| options | [GetBrightnessModeOptions](#getbrightnessmodeoptionsdeprecated) | No| Options for obtaining the screen brightness mode. This parameter is optional and is left blank by default.| 96 97**Example** 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 115Sets the screen brightness mode. 116 117**System capability**: SystemCapability.PowerManager.DisplayPowerManager.Lite 118 119**Parameters** 120| Name| Type| Mandatory| Description| 121| -------- | -------- | -------- | -------- | 122| options | [SetBrightnessModeOptions](#setbrightnessmodeoptionsdeprecated) | No | Options for setting the screen brightness mode. This parameter is optional and is left blank by default.| 123 124**Example** 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>This API is no longer maintained since API version 7. You are advised to use [window.setWindowKeepScreenOn()](../apis-arkui/arkts-apis-window-Window.md#setwindowkeepscreenon9). 144 145Sets whether to always keep the screen on. Call this API in **onShow()**. 146 147**System capability**: SystemCapability.PowerManager.DisplayPowerManager.Lite 148 149**Parameters** 150 151| Name| Type| Mandatory| Description| 152| -------- | -------- | -------- | -------- | 153| options | [SetKeepScreenOnOptions](#setkeepscreenonoptionsdeprecated) | No| Options for setting the screen to be steady on. This parameter is optional and is left blank by default.| 154 155**Example** 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 170Options for obtaining the screen brightness. 171 172**System capability**: SystemCapability.PowerManager.DisplayPowerManager.Lite 173 174| Name | Type | Mandatory| Description | 175| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | 176| success | (data: [BrightnessResponse](#brightnessresponsedeprecated)) => void | No | Called when an API call is successful. **data** is a return value of the [BrightnessResponse](#brightnessresponsedeprecated) type.| 177| fail | (data: string, code: number) => void | No | Called when an API call has failed. **data** indicates the error information, and **code** indicates the error code. | 178| complete | () => void | No | Called when an API call is complete. | 179 180## SetBrightnessOptions<sup>(deprecated)</sup> 181 182Options for setting the screen brightness. 183 184**System capability**: SystemCapability.PowerManager.DisplayPowerManager.Lite 185 186| Name | Type | Mandatory| Description | 187| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 188| value | number | Yes | Screen brightness. The value is an integer ranging from **1** to **255**.<br>- If the value is less than or equal to **0**, value **1** will be used.<br>- If the value is greater than **255**, value **255** will be used.<br>- 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.| 189| success | () => void | No | Called when API call is successful. | 190| fail | (data: string, code: number) => void | No | Called when an API call has failed. **data** indicates the error information, and **code** indicates the error code. | 191| complete | () => void | No | Called when an API call is complete. | 192 193## BrightnessResponse<sup>(deprecated)</sup> 194 195Defines a response that returns the screen brightness. 196 197**System capability**: SystemCapability.PowerManager.DisplayPowerManager.Lite 198 199| Name| Type| Readable| Writable| Description| 200| -------- | -------- | -------- | -------- | -------- | 201| value | number | Yes| No| Screen brightness. The value ranges from **1** to **255**.| 202 203## GetBrightnessModeOptions<sup>(deprecated)</sup> 204 205Options for obtaining the screen brightness mode. 206 207**System capability**: SystemCapability.PowerManager.DisplayPowerManager.Lite 208 209| Name | Type | Mandatory| Description | 210| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 211| success | (data: [BrightnessModeResponse](#brightnessmoderesponsedeprecated)) => void | No | Called when an API call is successful. **data** is a return value of the [BrightnessModeResponse](#brightnessmoderesponsedeprecated) type.| 212| fail | (data: string, code: number) => void | No | Called when an API call has failed. **data** indicates the error information, and **code** indicates the error code. | 213| complete | () => void | No | Called when an API call is complete. | 214 215## SetBrightnessModeOptions<sup>(deprecated)</sup> 216 217Options for setting the screen brightness mode. 218 219**System capability**: SystemCapability.PowerManager.DisplayPowerManager.Lite 220 221| Name | Type | Mandatory| Description | 222| -------- | ------------------------------------ | ---- | ------------------------------------------------------ | 223| mode | number | Yes | The value **0** indicates the manual adjustment mode, and the value **1** indicates the automatic adjustment mode.| 224| success | () => void | No | Called when API call is successful. | 225| fail | (data: string, code: number) => void | No | Called when an API call has failed. **data** indicates the error information, and **code** indicates the error code.| 226| complete | () => void | No | Called when an API call is complete. | 227 228## BrightnessModeResponse<sup>(deprecated)</sup> 229 230Defines a response that returns the screen brightness mode. 231 232**System capability**: SystemCapability.PowerManager.DisplayPowerManager.Lite 233 234| Name| Type| Readable| Writable| Description| 235| -------- | -------- | -------- | -------- | -------- | 236| mode | number | Yes| No| The value **0** indicates the manual adjustment mode, and the value **1** indicates the automatic adjustment mode.| 237 238## SetKeepScreenOnOptions<sup>(deprecated)</sup> 239 240Options for setting the screen to be steady on. 241 242**System capability**: SystemCapability.PowerManager.DisplayPowerManager.Lite 243 244| Name | Type | Mandatory| Description | 245| ------------ | ------------------------------------ | ---- | ------------------------------------------------------ | 246| keepScreenOn | boolean | Yes | The value **true** means to keep the screen steady on, and the value **false** indicates the opposite. | 247| success | () => void | No | Called when API call is successful. | 248| fail | (data: string, code: number) => void | No | Called when an API call has failed. **data** indicates the error information, and **code** indicates the error code.| 249| complete | () => void | No | Called when an API call is complete. | 250