power_manager - Power management
10/22/22Less than 1 minute
[Added in v8.3.3]
This module lets you control power-related behavior on the device. Using this API may affect battery life.
$power_manager.isIgnoringBatteryOptimizations([pkg])
pkg{string} Package name. Defaults to the current app package name.- Returns {boolean}
Returns whether “Ignore battery optimizations” is enabled for package pkg.
log("Ignore battery optimizations enabled: " + $power_manager.isIgnoringBatteryOptimizations())$power_manager.requestIgnoreBatteryOptimizations(forceRequest, pkg)
forceRequest{boolean} Iffalseand ignoring battery optimizations is already enabled, no request is made. Iftrue, it will request regardless. Defaultfalse.pkg{boolean} Package name to ignore battery optimizations for. Defaults to the current app package name.
Request the user to ignore battery optimizations for package pkg. The system will show a confirmation dialog. This is asynchronous and no result is returned.
if (!$power_manager.isIgnoringBatteryOptimizations()) {
toastLog("Ignore battery optimizations is not enabled. Requesting...");
$power_manager.requestIgnoreBatteryOptimizations();
}