power_manager

October 22, 2022

power_manager

[New in v8.3.3]

This module allows you to control the power state of your device. Using this API could potentially affect the battery life of the device.

$power_manager.isIgnoringBatteryOptimizations([pkg])

  • pkg {string} package name, default is the name of this application package
  • return {boolean}

Returns if [ignoringBatteryOptimizations] is currently enabled for the application pkg.

log("Is Ignoring Battery Optimizations enabled: " + $power_manager.isIgnoringBatteryOptimizations())

$power_manager.requestIgnoreBatteryOptimizations(forceRequest, pkg)

  • forceRequest {boolean} If false and ignoring battery optimizations is currently enabled, the request is not executed; if true, all requests ignore battery optimizations. The default is false.
  • pkg {boolean} The name of the package to ignore battery optimization. Default is the name of this application package.

Request the user to ignore the battery optimization of the application pkg. A popup window will be displayed prompting the user to confirm this, this process is asynchronous and the confirmation result will not be returned.

if (! $power_manager.isIgnoringBatteryOptimizations()) {
    toastLog("Ignoring battery optimizations not enabled, request in progress...") ;
    $power_manager.requestIgnoreBatteryOptimizations();
}
Last update:
Contributors: Bruce