android_power_manager 1.0.0 copy "android_power_manager: ^1.0.0" to clipboard
android_power_manager: ^1.0.0 copied to clipboard

PlatformAndroid

A Flutter plugin for Android for invoking Power Manager api.

Android Power Manager plugin for Flutter #

A Flutter plugin for Android for invoking Power Manager api.

Note: This plugin is still under development, and some APIs might not be available yet. Feedback welcome and Pull Requests are most welcome!

Installation #

First, add android_power_manager as a dependency in your pubspec.yaml file.

Android #

If you want to request ignoring battery optimizations please specify your permission in the application manifest android/app/src/main/AndroidManifest.xml:

<manifest...>
  <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
</manifest...>

Example #

Check battery optimizations if it is ignoring

import 'package:android_power_manager/android_power_manager.dart';

// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
  // If the widget was removed from the tree while the asynchronous platform
  // message was in flight, we want to discard the reply rather than calling
  // setState to update our non-existent appearance.
  if (!mounted) return;
  String isIgnoringBatteryOptimizations = await _checkBatteryOptimizations();
  setState(() {
    _isIgnoringBatteryOptimizations = isIgnoringBatteryOptimizations;
  });
}

Request to ignore battery optimizations

final success = await AndroidPowerManager.requestIgnoreBatteryOptimizations();
11
likes
130
pub points
85%
popularity

Publisher

verified publisherdemen.org

A Flutter plugin for Android for invoking Power Manager api.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on android_power_manager