• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Screen Brightness
2
3> **NOTE**
4> - The APIs of this module are no longer maintained since API version 7. You are advised to use [`@ohos.brightness`](js-apis-brightness.md).
5>
6> - 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.
7
8
9## Modules to Import
10
11
12```js
13import brightness from '@system.brightness';
14```
15
16
17## brightness.getValue
18
19getValue(Object): void
20
21Obtains the current screen brightness.
22
23**System capability**: SystemCapability.PowerManager.DisplayPowerManager
24
25**Parameters**
26
27| Name| Type| Mandatory| Description|
28| -------- | -------- | -------- | -------- |
29| success | (data: [BrightnessResponse](#brightnessresponse)) => void | No| Called when API call is successful.|
30| fail | (data: string, code: number) => void | No| Called when API call has failed.|
31| complete | () => void | No| Called when API call is complete.|
32
33**Return value of success()**
34
35| Name| Type| Description|
36| -------- | -------- | -------- |
37| value | number | Screen brightness. The value is an integer ranging from **1** to **255**.|
38
39
40**Example**
41
42  ```js
43  export default {
44    getValue() {
45      brightness.getValue({
46        success: function(data){
47          console.log('success get brightness value:' + data.value);
48        },
49        fail: function(data, code) {
50          console.log('get brightness fail, code: ' + code + ', data: ' + data);
51        },
52      });
53    },
54  }
55  ```
56
57
58## brightness.setValue
59
60setValue(Object): void
61
62Sets the screen brightness.
63
64**System capability**: SystemCapability.PowerManager.DisplayPowerManager
65
66**Parameters**
67
68| Name| Type| Mandatory| Description|
69| -------- | -------- | -------- | -------- |
70| 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.|
71| success | () => void | No| Called when API call is successful.|
72| fail | (data: string, code: number) => void | No| Called when API call has failed.|
73| complete | () => void | No| Called when API call is complete.|
74
75**Example**
76
77  ```js
78  export default {
79    setValue() {
80      brightness.setValue({
81        value: 100,
82        success: function(){
83          console.log('handling set brightness success.');
84        },
85        fail: function(data, code){
86          console.log('handling set brightness value fail, code:' + code + ', data: ' + data);
87        },
88      });
89    },
90  }
91  ```
92
93
94## brightness.getMode
95
96getMode(Object): void
97
98Obtains the screen brightness adjustment mode.
99
100**System capability**: SystemCapability.PowerManager.DisplayPowerManager
101
102**Parameters**
103
104| Name| Type| Mandatory| Description|
105| -------- | -------- | -------- | -------- |
106| success | (data: [BrightnessModeResponse](#brightnessmoderesponse)) => void | No| Called when API call is successful.|
107| fail | (data: string, code: number) => void | No| Called when API call has failed.|
108| complete | () => void | No| Called when API call is complete.|
109
110**Return value of success()**
111
112| Name| Type| Description|
113| -------- | -------- | -------- |
114| mode | number | The value can be **0** or **1**.<br>- **0**: manual adjustment<br>- **1**: automatic adjustment|
115
116**Example**
117
118  ```js
119  export default {
120    getMode() {
121      brightness.getMode({
122        success: function(data){
123          console.log('success get mode:' + data.mode);
124        },
125        fail: function(data, code){
126          console.log('handling get mode fail, code:' + code + ', data: ' + data);
127        },
128      });
129    },
130  }
131  ```
132
133
134## brightness.setMode
135
136setMode(Object): void
137
138Sets the screen brightness adjustment mode.
139
140**System capability**: SystemCapability.PowerManager.DisplayPowerManager
141
142**Parameters**
143| Name| Type| Mandatory| Description|
144| -------- | -------- | -------- | -------- |
145| mode | number | Yes| The value can be **0** or **1**.<br>- **0**: manual adjustment<br>- **1**: automatic adjustment|
146| success | () => void | No| Called when API call is successful.|
147| fail | (data: string, code: number) => void | No| Called when API call has failed.|
148| complete | () => void | No| Called when API call is complete.|
149
150**Example**
151
152  ```js
153  export default {
154    setMode() {
155      brightness.setMode({
156        mode: 1,
157        success: function(){
158        console.log('handling set mode success.');
159      },
160       fail: function(data, code){
161         console.log('handling set mode fail, code:' + code + ', data: ' + data);
162       },
163      });
164    },
165  }
166  ```
167
168
169## brightness.setKeepScreenOn
170
171setKeepScreenOn(Object): void
172
173Sets whether to always keep the screen on. Call this API in **onShow()**.
174
175**System capability**: SystemCapability.PowerManager.DisplayPowerManager
176
177**Parameters**
178| Name| Type| Mandatory| Description|
179| -------- | -------- | -------- | -------- |
180| keepScreenOn | boolean | Yes| Whether to keep the screen on.|
181| success | () => void | No| Called when API call is successful.|
182| fail | (data: string, code: number) => void | No| Called when API call has failed.|
183| complete | () => void | No| Called when API call is complete.|
184
185**Example**
186
187  ```js
188  export default {
189    setKeepScreenOn() {
190      brightness.setKeepScreenOn({
191        keepScreenOn: true,
192        success: function () {
193          console.log('handling set keep screen on success.')
194        },
195        fail: function (data, code) {
196          console.log('handling set keep screen on fail, code:' + code + ', data: ' + data);
197        },
198      });
199    },
200  }
201  ```
202##
203
204## BrightnessResponse
205
206| Name| Type | Description|
207| -------- | -------- | -------- |
208| value | number | Screen brightness. The value is an integer ranging from **1** to **255**.|
209
210## BrightnessModeResponse
211
212| Name| Type | Description|
213| -------- | -------- | -------- |
214| mode | number | The value can be **0** or **1**.<br> - **0**: manual adjustment<br>- **0**: manual adjustment|
215