• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.brightness (Screen Brightness)
2
3The **brightness** module provides an API for setting the screen brightness.
4
5> **NOTE**
6>
7> - 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.
8>
9> - The APIs provided by this module are system APIs.
10
11## Modules to Import
12
13```js
14import brightness from '@ohos.brightness';
15```
16
17## brightness.setValue
18
19setValue(value: number): void
20
21Sets the screen brightness.
22
23**System API**: This is a system API.
24
25**System capability**: SystemCapability.PowerManager.DisplayPowerManager
26
27**Parameters**
28
29| Name| Type  | Mandatory| Description                   |
30| ------ | ------ | ---- | ----------------------- |
31| value  | number | Yes  | Brightness value. The value ranges from 0 to 255.|
32
33**Error codes**
34
35For details about the error codes, see [Screen Brightness Error Codes](../errorcodes/errorcode-brightness.md).
36
37| Code  | Error Message   |
38|---------|---------|
39| 4700101 | Operation failed. Cannot connect to service.|
40
41**Example**
42
43```js
44try {
45    brightness.setValue(128);
46} catch(err) {
47    console.error('set brightness failed, err: ' + err);
48}
49```
50