搜索插件、代码仓与 APP 分类

插件详情v1.1.2

disable_battery_optimization

用于检查和禁用电池优化的 Flutter 插件。还显示在小米、红米、三星、OPPO、华为、一加等设备上禁用优化的自定义步骤

Android
近 30 天下载
1.4万
喜欢数
129
Pub 分数
150

安装插件

flutter pub add disable_battery_optimization

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 插件,用于检查并禁用 Android 设备上的电池优化,特别适用于需要后台执行的应用程序。它为小米、三星、OPPO、华为和一加等主流品牌提供定制化的操作指南,指导用户完成手动设置,以确保应用性能不受中断。该插件通过防止操作系统限制应用活动,增强了位置跟踪、推送通知和后台同步等服务的可靠性。

适合场景

  • 后台任务执行
  • 后台位置跟踪
  • 推送通知的可靠性
  • 长时间数据同步
  • 应用性能优化
  • 电池寿命管理

主要特点

  • 设备特定优化指南
  • 自动电池优化检查
  • 支持主要的安卓品牌
  • 与 Flutter 的简单集成
  • 清除用户指令
  • 跨设备兼容性

适合对象

  • 需要持久后台进程的应用
  • 面向 Android OEM 的开发者
  • 需要可靠前台执行的服务
  • 实时更新的移动应用
  • 企业或实用程序应用程序

使用建议

  • 仅需 Android 平台
  • 某些步骤需要用户交互
  • 限于列出的安卓设备制造商
  • 可能需要权限请求
  • 不适用于 iOS 设备

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

disable_battery_optimization

Flutter plugin to check and disable battery optimizations. Also shows custom steps to disable the manufacturer specific optimizations on devices like mi, xiaomi, samsung, oppo, huawei, oneplus etc


Auto start
bool isAutoStartEnabled = await DisableBatteryOptimization.isAutoStartEnabled;

This will return true, for the devices which doesn't support auto start configuration as well for the devices on which, user has clicked on positive action for the auto start configuration dialog.

await DisableBatteryOptimization.showEnableAutoStartSettings("Enable Auto Start", "Follow the steps and enable the auto start of this app");

This will show a dialog with steps to enable auto start permission on the current device (if it's available)

Note: We cannot determine if the user has actually enabled the auto start permission or not. We can only show a dialog with the steps to enable.


Android Battery Optimization
bool isBatteryOptimizationDisabled = await DisableBatteryOptimization.isBatteryOptimizationDisabled;

This will return true, only if the user has disabled the 'native' battery optimization for this app.

await DisableBatteryOptimization.showDisableBatteryOptimizationSettings();

This will ask for the permission to disable battery optimization for the app.


Manufacturer specific Battery Optimization
bool isManBatteryOptimizationDisabled = await DisableBatteryOptimization.isManufacturerBatteryOptimizationDisabled;

This will return true, for the devices which doesn't support manufacturer specific battery optimization configuration as well for the devices on which, user has clicked on positive action for the manufacturer specific battery optimization configuration dialog.

await DisableBatteryOptimization.showDisableManufacturerBatteryOptimizationSettings("Your device has additional battery optimization", "Follow the steps and disable the optimizations to allow smooth functioning of this app");

This will show a dialog with steps to disable the manufacturer specific battery optimization on the current device (if it's available)

Note: We cannot determine if the user has actually disabled the manufacturer specific battery optimization or not. We can only show a dialog with the steps to disable it.


There are other helper methods available to check if all the permissions are enabled or disabled.

await DisableBatteryOptimization.isAllBatteryOptimizationDisabled
await DisableBatteryOptimization.showDisableAllOptimizationsSettings

所属分类

源码仓库

使用此插件的项目