Device.setBrightness()
Overview
Controls the brightness of the hardware screen backlight ranging from fully off to maximum brightness. Setting brightness to 0 may yield different results depending on how the device manufacturer implemented the setting.
Setting the brightness to 0 means the screen may be hard to see. We recommend providing a way to restore it that doesn't require interacting with the screen. For example, use a hardware key press that triggers a script to restore the brightness. Refer to Example 2.
The brightness level set using this API can be overridden by adjusting the system setting in Android.
Added in version 2.1.43
Android only
Format
Device.setBrightness(brightness);
Parameter | Description | Type | Required | Notes |
---|---|---|---|---|
brightness | Number value ranging from 0-100 inclusive where 0 is fully off and 100 is the maximum screen backlight brightness. | Number | Required |
Values below 0 or above 100 are ignored and a Velocity error message is logged. |
Example 1
/* Sets the backlight brightness fully off.
*/
Device.setBrightness(0);
Example 2
/* Turn the backlight fully off after hardware key F7
has been pressed.
*/
function BacklightOff(event) {
Device.setBrightness(0);
}
/* Turn the backlight fully on after hardware key F8
has been pressed.
*/
function BacklightOn(event) {
Device.setBrightness(100);
}
WLEvent.on("OnKey<E041>", BacklightOff);
WLEvent.on("OnKey<E042>", BacklightOn);