onPowerSaveChange static method

void onPowerSaveChange(
  1. dynamic callback(
    1. bool
    )
)

Subscribe to state changes in OS power-saving system.

Fired when the state of the operating-system's "Power Saving" mode changes. Your callback will be provided with a bool showing whether "Power Saving" is enabled or disabled. Power Saving mode can throttle certain services in the background, such as HTTP requests or GPS.

NOTE: You can manually request the current-state of "Power Saving" mode with the method DeviceSettings.isPowerSaveMode.

iOS

iOS Power Saving mode can be engaged manually by the user in Settings -> Battery or from an automatic OS dialog.

Android

Android Power Saving mode can be engaged manually by the user in Settings -> Battery -> Battery Saver or automatically with a user-specified "threshold" (eg: 15%).

Example

BackgroundGeolocation.onPowerSaveChange((bool isPowerSaveMode) {
  print('[onPowerSaveChange: ${isPowerSaveMode}');
});

Implementation

static void onPowerSaveChange(Function(bool) callback) {
  if (_eventsPowerSaveChange == null) {
    _eventsPowerSaveChange = _eventChannelPowerSaveChange
        .receiveBroadcastStream()
        .map((dynamic isPowerSaveMode) => isPowerSaveMode as bool);
  }
  _registerSubscription(_eventsPowerSaveChange!.listen(callback), callback);
}