Options
All
  • Public
  • Public/Protected
  • All
Menu

Module power_manager

This module can let you control the power policy of this application, by ignoring battery optimization to let this application run in background. Using this API may cause the battery life of the device to be affected.

Index

Functions

isIgnoringBatteryOptimizations

  • isIgnoringBatteryOptimizations(pkg?: string): boolean
  • Returns whether the application with the specify package name is enabled to ignore battery optimization.

    example
    "nodejs";
    const { ignoreBatteryOptimization } = require('power_manager');
    console.log('ignoreBatteryOptimization:', ignoreBatteryOptimization());
    

    Parameters

    • pkg: string = ...

      The package name of the application, default to the package name of this application.

    Returns boolean

    Whether the application is enabled to ignore battery optimization.

requestIgnoreBatteryOptimizations

  • requestIgnoreBatteryOptimizations(forceRequest?: boolean, pkg?: string): void
  • Request user to ignore battery optimization of the application with the specify package name. System will pop up a dialog to ask user to confirm, this process is asynchronous, the result of the confirmation will not be returned.

    example
    "nodejs";
    const { ignoreBatteryOptimization, requestIgnoreBatteryOptimizations } = require('power_manager');
    if (!ignoreBatteryOptimization()) {
       console.log('requestIgnoreBatteryOptimizations');
       requestIgnoreBatteryOptimizations();
    }
    

    Parameters

    • forceRequest: boolean = false

      If false and the current application is enabled to ignore battery optimization, the request will not be executed; if true, the request will always be executed. The default is false.

    • pkg: string = ...

      The package name of the application to ignore battery optimization. The default is the package name of this application.

    Returns void