The screen brightness APIs let you read and set the device screen brightness. Use my.getScreenBrightness to read the current value and my.setScreenBrightness to set it. Brightness is in the range 0–1.
Gets the current screen brightness value.
my.getScreenBrightness({
success: (res) => {
my.alert({
content: "Current screen brightness: " + res.brightness,
});
},
});
| Property | Type | Required | Description |
|---|---|---|---|
success | Function | No | Callback function upon call success. |
fail | Function | No | Callback function upon call failure. |
complete | Function | No | Callback function upon call completion (executed whether the call succeeds or fails). |
| Property | Type | Description |
|---|---|---|
brightness | Number | Current screen brightness, range 0–1. |
Sets the screen brightness.
// Set brightness to 0.5 (50%)
my.setScreenBrightness({
brightness: 0.5,
success: () => {
my.alert({ content: "Brightness updated" });
},
});
| Property | Type | Required | Description |
|---|---|---|---|
brightness | Number | Yes | Screen brightness to set, range 0–1. |
success | Function | No | Callback function upon call success. |
fail | Function | No | Callback function upon call failure. |
complete | Function | No | Callback function upon call completion (executed whether the call succeeds or fails). |