# Screen Brightness
Control of the screen brightness.
# Manifest Declaration
You need to declare the use of this API in the manifest's features member:
{"name": "system.brightness"}
# Module Import
Before using this service in a component, you need to import the module in the script section of the UX document.
import brightness from '@system.brightness'
Or
let brightness = require("@system.brightness")
# Methods
This service has the following methods:
getValue({success,fail,complete})setValue({value,success,fail,complete})getMode({success,fail,complete})setMode({mode,success,fail,complete})setKeepScreenOn({keepScreenOn,success,fail,complete})
# getValue({success,fail,complete})
Method to get the current screen brightness level.
# Arguments
This method requires an object with the following attributes:
success(function(object)). Optional callback function for success. The function has anobjectargument with the following attributes:value(number). Screen brightness. The value is an integer from0to255.
fail(function()). Optional callback function for failure.complete(function()). Optional callback function for completion.
Example:
brightness.getValue({
success: function(ret) {
console.log("handling success");
}
})
# setValue({value,success,fail,complete})
Method to set the screen brightness level.
# Arguments
This method requires an object with the following attributes:
value(number). Mandatory attribute with the value of the screen brightness. The value is an integer from0to255.success(function()). Optional callback function for success.fail(function()). Optional callback function for failure.complete(function()). Optional callback function for completion.
Note
- If the
valueparameter is0or smaller, the system will apply the value1. - If the
valueparameter is greater than255, the system will apply the value255. - If the
valueparameter is a decimal number, the system will take only the integer part.
Example:
brightness.setValue({
success:function(data){console.log("handling success"); },
fail: function(data, code){console.log("handling fail, code=" + code);}
})
# getMode({success,fail,complete})
Method to get the current setup mode of the screen brightness.
# Arguments
This method requires an object with the following attributes:
success(function(res)). Optional callback function for success. The function has anobjectargument with the following attributes:mode(number). Indicates the setup mode of the brightness:0for manual adjustment and1for automatic adjustment.
fail(function()). Optional callback function for failure.complete(function()). Optional callback function for completion.
Example:
brightness.getMode({
success:function(ret){console.log("mode is: " + ret.mode);}
})
# setMode({mode,success,fail,complete})
Method to set the screen brightness adjustment mode (manual or automatic).
# Arguments
This method requires an object with the following attributes:
mode(number). Mandatory attribute with the mode of the screen brightness adjustment. The value is an integer:0for manual adjustment, and1for an automatic control.success(function()). Optional callback function for success.fail(function()). Optional callback function for failure.complete(function()). Optional callback function for completion.
Note
- If the
valueparameter is0or smaller, the system will apply the value1. - If the
valueparameter is greater than255, the system will apply the value255. - If the
valueparameter is a decimal number, the system will take only the integer part.
Example:
brightness.setMode({
mode: 1,
success:function(data){console.log("handling success"); },
fail: function(data, code){console.log("handling fail, code=" + code);}
})
# setKeepScreenOn({keepScreenOn,success,fail,complete})
Method to keep the screen on.
# Arguments
This method requires an object with the following attributes:
keepScreenOn(boolean). Mandatory flag that indicates if the system need to keep the screen steady on (true) or not.success(function()). Optional callback function for success.fail(function()). Optional callback function for failure.complete(function()). Optional callback function for completion.
Example:
brightness.setKeepScreenOn({
keepScreenOn: true,
success: function () {
console.log(`handling success`)
},
fail: function (data, code) {
}
})
← Media Queries Sensors →