js-apis-brightness.md 1.2 KB
Newer Older
S
shawn_he 已提交
1
# @ohos.brightness (Screen Brightness)
Z
zengyawen 已提交
2

S
shawn_he 已提交
3
The **brightness** module provides an API for setting the screen brightness.
S
shawn_he 已提交
4

S
shawn_he 已提交
5 6 7 8 9
> **NOTE**
>
> - 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.
>
> - The APIs provided by this module are system APIs.
S
shawn_he 已提交
10 11

## Modules to Import
Z
zengyawen 已提交
12

S
shawn_he 已提交
13
```js
Z
zengyawen 已提交
14 15 16
import brightness from '@ohos.brightness';
```

S
shawn_he 已提交
17
## brightness.setValue
W
wusongqing 已提交
18

S
shawn_he 已提交
19
setValue(value: number): void
W
wusongqing 已提交
20

S
shawn_he 已提交
21
Sets the screen brightness.
Z
zengyawen 已提交
22

S
shawn_he 已提交
23
**System API**: This is a system API.
Z
zengyawen 已提交
24

S
shawn_he 已提交
25
**System capability:** SystemCapability.PowerManager.DisplayPowerManager
Z
zengyawen 已提交
26

S
shawn_he 已提交
27
**Parameters**
Z
zengyawen 已提交
28

S
shawn_he 已提交
29 30 31 32 33 34 35 36
| Name| Type  | Mandatory| Description                   |
| ------ | ------ | ---- | ----------------------- |
| value  | number | Yes  | Brightness value. The value ranges from 0 to 255.|

**Error codes**

For details about the error codes, see [Screen Brightness Error Codes](../errorcodes/errorcode-brightness.md).

S
shawn_he 已提交
37
| ID  | Error Message   |
S
shawn_he 已提交
38
|---------|---------|
S
shawn_he 已提交
39
| 4700101 | If connecting to the service failed. |
Z
zengyawen 已提交
40

S
shawn_he 已提交
41 42
**Example**

S
shawn_he 已提交
43
```js
S
shawn_he 已提交
44 45 46 47 48
try {
    brightness.setValue(128);
} catch(err) {
    console.error('set brightness failed, err: ' + err);
}
S
shawn_he 已提交
49
```