Android Battery Optimization
Android Battery Optimization
@capawesome-team/capacitor-android-battery-optimization
Capacitor plugin to access battery optimization settings on Android.
Maintainers¶
Maintainer | GitHub | Social |
---|---|---|
Robin Genz | robingenz | @robin_genz |
Sponsorware¶
This project is available as Sponsorware.
Sponsorware is a release strategy for open-source software that enables developers to be compensated for their open-source work with fewer downsides than traditional open-source funding models. (Source)
This means...
- The source code will be published as soon as our GitHub Sponsors goal is reached.
- Any GitHub sponsor with a sponsorware tier gets immediate access to our sponsors-only repository and can start using the project right away.
Terms¶
This project is licensed under the terms of the MIT license.
However, we kindly ask you to respect our fair use policy:
- Please don't distribute the source code of the sponsors-only repository. You may freely use it for public, private or commercial projects, privately fork or mirror it, but please don't make the source code public, as it would counteract the sponsorware strategy.
- If you cancel your subscription, you're automatically removed as a collaborator and will miss out on all future updates. However, you may use the latest version that's available to you as long as you like.
Demo¶
A working example can be found here: robingenz/capacitor-plugin-demo
Android |
---|
![]() |
Roadmap¶
This plugin is still under development. We have already received feature requests. This is our approximate roadmap:
Q4 2022 |
---|
- Extended Android Custom ROM support |
⚠️ Disclaimer: This roadmap does not represent a commitment, guarantee, obligation or promise to deliver any product or feature, or to deliver any product and feature by any particular date, and is intended to outline the general development plans. You should not rely on this roadmap to make any sponsorship decision.
FAQ¶
- Which platforms are supported?
This plugin supports Android (API Level 23+). - Which Capacitor versions are supported?
This plugin supports Capacitor 4. - What do I do when I have a feature request?
Please submit your feature request here. We will then review it and possibly put it on our roadmap. - What do I do when I have found a bug?
Bug reports have top priority. Please submit your bug report here. We will take a look at it as soon as possible.
Installation¶
See Getting started with Insiders and follow the instructions to install the plugin.
After that, follow the platform-specific instructions in the section Android.
Android¶
This API requires the following permissions be added to your AndroidManifest.xml
before the application
tag if you want to request direct exemption from Power Management features:
⚠️ Attention: Google Play policies prohibit apps from requesting direct exemption from Power Management features in Android 6.0+ (Doze and App Standby) unless the core function of the app is adversely affected. Source
Configuration¶
No configuration required for this plugin.
Usage¶
import { Capacitor } from '@capacitor/core';
import { BatteryOptimization } from '@capawesome-team/capacitor-android-battery-optimization';
const isBatteryOptimizationEnabled = async () => {
if (Capacitor.getPlatform() !== 'android') {
return false;
}
const { enabled } = await BatteryOptimization.isBatteryOptimizationEnabled();
return enabled;
};
const openBatteryOptimizationSettings = async () => {
if (Capacitor.getPlatform() !== 'android') {
return;
}
await BatteryOptimization.openBatteryOptimizationSettings();
};
const requestIgnoreBatteryOptimization = async () => {
if (Capacitor.getPlatform() !== 'android') {
return;
}
await BatteryOptimization.requestIgnoreBatteryOptimization();
};
API¶
isBatteryOptimizationEnabled()
openBatteryOptimizationSettings()
requestIgnoreBatteryOptimization()
- Interfaces
isBatteryOptimizationEnabled()¶
Returns whether or not battery optimization is enabled.
Only available for Android.
Returns: Promise<IsBatteryOptimizationEnabledResult>
Since: 0.0.1
openBatteryOptimizationSettings()¶
Opens the battery optimization settings page.
Only available for Android.
Since: 0.0.1
requestIgnoreBatteryOptimization()¶
Requests the battery optimization ignore permission.
This method needs the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
manifest permission.
Use this method only if your app meets an acceptable use case (see Google Play Policy).
Only available for Android.
Since: 0.0.1
Interfaces¶
IsBatteryOptimizationEnabledResult¶
Prop | Type | Description | Since |
---|---|---|---|
enabled |
boolean |
Whether or not battery optimization is enabled. | 0.0.1 |
Changelog¶
See CHANGELOG.md.
License¶
See LICENSE.