FLUTTER ECOSYSTEM

Bhat015/optimize_battery

用於檢查電池優化狀態、開啟優化設定並停用優化的 Flutter 外掛程式。

優化電池 專案封面
Stars
10
Forks
19
最近推送(UTC)
2024年3月13日
專案狀態
未封存
Ganesh Bhat GitHub avatar
GITHUB User

Ganesh Bhat ↗

Bengaluru
語言DartJavaRubySwiftObjective-C

此儲存庫發佈的套件

使用的依賴

依賴清單 3 項
  • flutter{"sdk":"flutter"}
  • flutter_test開發依賴{"sdk":"flutter"}
  • flutter_lints開發依賴^1.0.0

原始 README

以下為英文專案原文快照,最新內容請造訪 GitHub。

展開 / 收合專案 README

optimize_battery

Check for application battery optimization status and open settings or disable it

Getting Started

Check if app is ignoring battery optimization

  OptimizeBattery.isIgnoringBatteryOptimizations().then((onValue) {
      setState(() {
          if (onValue) {
              // Igonring Battery Optimization
          } else {
              // App is under battery optimization
          }
      });
  });

Take user to battery optimization settings

  OptimizeBattery.openBatteryOptimizationSettings()

Show battery optimization disable dialog

  OptimizeBattery.stopOptimizingBatteryUsage();

This opens the battery optimization disable dialog.

Example

Add the permission in Mainfest file

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

It uses the intent(ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS). Which is not recommended unless its an excemtion case. Such as the applications main functionality needs the battery optimisation to be disabled.

Read more here : https://developer.android.com/training/monitoring-device-state/doze-standby#exemption-cases

Credit

This plugin is inspired from battery_optimization but with supporting Null safety and Android V2 embedding