npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@capawesome/capacitor-battery

v0.1.2

Published

Capacitor plugin to access battery information on Android, iOS, and Web.

Readme

Capacitor Battery Plugin

Capacitor plugin to access battery information.

Features

The Capacitor Battery plugin is one of the most complete battery monitoring solutions for Capacitor apps. Here are some of the key features:

  • 🔋 Battery level: Read the current battery level of the device.
  • Battery state: Read whether the device is charging, full or unplugged.
  • 🪫 Low power mode: Read whether the low power mode is enabled.
  • 👂 Change events: Listen for changes to the battery level, state and low power mode.
  • 🌐 Web support: Read the battery level and state on supported browsers.
  • 🤝 Compatibility: Works alongside the Android Battery Optimization plugin.
  • 📦 CocoaPods & SPM: Supports CocoaPods and Swift Package Manager for iOS.
  • 🔁 Up-to-date: Always supports the latest Capacitor version.

Missing a feature? Just open an issue and we'll take a look!

Use Cases

The Battery plugin is typically used whenever an app should adapt its behavior to the device's power situation, for example:

  • Energy-aware features: Reduce background work, animations, or sync frequency when the battery level is low.
  • Low power mode handling: Disable power-hungry features when the user has enabled low power mode.
  • Charging-dependent tasks: Only start heavy tasks such as large downloads while the device is charging.
  • Status display: Show the current battery level and charging state inside your app, for example in a kiosk or fleet app.
  • Reacting to changes: Warn the user when the battery level drops by listening for change events.

Compatibility

| Plugin Version | Capacitor Version | Status | | -------------- | ----------------- | -------------- | | 0.x.x | >=8.x.x | Active support |

Guides

Installation

You can use our AI-Assisted Setup to install the plugin. Add the Capawesome Skills to your AI tool using the following command:

npx skills add capawesome-team/skills --skill capacitor-plugins

Then use the following prompt:

 Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-battery` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capawesome/capacitor-battery
npx cap sync

This plugin does not require any additional configuration or permissions on Android or iOS.

On the Web, the battery level and state are only available in browsers that implement the Battery Status API (Chromium-based browsers). The low power mode is not available on the Web.

Configuration

No configuration required for this plugin.

Usage

The following examples show how to get the current battery level and state, check if low power mode is enabled, listen for battery changes, and remove all listeners.

Get the current battery level

Read the current battery level of the device as a value between 0.0 and 1.0:

import { Battery } from '@capawesome/capacitor-battery';

const getBatteryLevel = async () => {
  const { level } = await Battery.getBatteryLevel();
  return level;
};

Get the current battery state

Check whether the device is charging, full or unplugged:

import { Battery } from '@capawesome/capacitor-battery';

const getBatteryState = async () => {
  const { state } = await Battery.getBatteryState();
  return state;
};

Check if low power mode is enabled

Read whether the low power mode (power saver mode on Android, Low Power Mode on iOS) is currently enabled. Only available on Android and iOS:

import { Battery } from '@capawesome/capacitor-battery';

const isLowPowerModeEnabled = async () => {
  const { enabled } = await Battery.isLowPowerModeEnabled();
  return enabled;
};

Listen for battery changes

Get notified when the battery level, battery state or low power mode changes. The device is only observed while at least one listener is attached. The lowPowerModeChange event is only available on Android and iOS:

import { Battery } from '@capawesome/capacitor-battery';

const addBatteryLevelChangeListener = async () => {
  await Battery.addListener('batteryLevelChange', event => {
    console.log('Battery level changed:', event.level);
  });
};

const addBatteryStateChangeListener = async () => {
  await Battery.addListener('batteryStateChange', event => {
    console.log('Battery state changed:', event.state);
  });
};

const addLowPowerModeChangeListener = async () => {
  await Battery.addListener('lowPowerModeChange', event => {
    console.log('Low power mode changed:', event.enabled);
  });
};

Remove all listeners

Remove all listeners that were registered for this plugin:

import { Battery } from '@capawesome/capacitor-battery';

const removeAllListeners = async () => {
  await Battery.removeAllListeners();
};

API

getBatteryLevel()

getBatteryLevel() => Promise<GetBatteryLevelResult>

Get the current battery level of the device.

On the web, this is only supported in browsers that implement the Battery Status API (Chromium-based browsers).

Only available on Android, iOS and Web.

Returns: Promise<GetBatteryLevelResult>

Since: 0.1.0


getBatteryState()

getBatteryState() => Promise<GetBatteryStateResult>

Get the current battery state of the device.

On the web, this is only supported in browsers that implement the Battery Status API (Chromium-based browsers).

Only available on Android, iOS and Web.

Returns: Promise<GetBatteryStateResult>

Since: 0.1.0


isLowPowerModeEnabled()

isLowPowerModeEnabled() => Promise<IsLowPowerModeEnabledResult>

Get whether the low power mode is currently enabled.

On Android, this refers to the power saver mode. On iOS, this refers to the Low Power Mode.

Only available on Android and iOS.

Returns: Promise<IsLowPowerModeEnabledResult>

Since: 0.1.0


addListener('batteryLevelChange', ...)

addListener(eventName: 'batteryLevelChange', listenerFunc: (event: BatteryLevelChangeEvent) => void) => Promise<PluginListenerHandle>

Listen for changes to the battery level of the device.

The device is only observed while at least one listener is attached.

On the web, this is only supported in browsers that implement the Battery Status API (Chromium-based browsers).

Only available on Android, iOS and Web.

| Param | Type | | ------------------ | ----------------------------------------------------------------------------------------------- | | eventName | 'batteryLevelChange' | | listenerFunc | (event: BatteryLevelChangeEvent) => void |

Returns: Promise<PluginListenerHandle>

Since: 0.1.0


addListener('batteryStateChange', ...)

addListener(eventName: 'batteryStateChange', listenerFunc: (event: BatteryStateChangeEvent) => void) => Promise<PluginListenerHandle>

Listen for changes to the battery state of the device.

The device is only observed while at least one listener is attached.

On the web, this is only supported in browsers that implement the Battery Status API (Chromium-based browsers).

Only available on Android, iOS and Web.

| Param | Type | | ------------------ | ----------------------------------------------------------------------------------------------- | | eventName | 'batteryStateChange' | | listenerFunc | (event: BatteryStateChangeEvent) => void |

Returns: Promise<PluginListenerHandle>

Since: 0.1.0


addListener('lowPowerModeChange', ...)

addListener(eventName: 'lowPowerModeChange', listenerFunc: (event: LowPowerModeChangeEvent) => void) => Promise<PluginListenerHandle>

Listen for changes to the low power mode of the device.

The device is only observed while at least one listener is attached.

Only available on Android and iOS.

| Param | Type | | ------------------ | ----------------------------------------------------------------------------------------------- | | eventName | 'lowPowerModeChange' | | listenerFunc | (event: LowPowerModeChangeEvent) => void |

Returns: Promise<PluginListenerHandle>

Since: 0.1.0


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all listeners for this plugin.

Since: 0.1.0


Interfaces

GetBatteryLevelResult

| Prop | Type | Description | Since | | ----------- | ------------------- | --------------------------------------------------------------------------- | ----- | | level | number | The current battery level of the device as a value between 0.0 and 1.0. | 0.1.0 |

GetBatteryStateResult

| Prop | Type | Description | Since | | ----------- | ----------------------------------------------------- | ---------------------------------------- | ----- | | state | BatteryState | The current battery state of the device. | 0.1.0 |

IsLowPowerModeEnabledResult

| Prop | Type | Description | Since | | ------------- | -------------------- | ------------------------------------------------ | ----- | | enabled | boolean | Whether the low power mode is currently enabled. | 0.1.0 |

PluginListenerHandle

| Prop | Type | | ------------ | ----------------------------------------- | | remove | () => Promise<void> |

BatteryLevelChangeEvent

| Prop | Type | Description | Since | | ----------- | ------------------- | --------------------------------------------------------------------------- | ----- | | level | number | The current battery level of the device as a value between 0.0 and 1.0. | 0.1.0 |

BatteryStateChangeEvent

| Prop | Type | Description | Since | | ----------- | ----------------------------------------------------- | ---------------------------------------- | ----- | | state | BatteryState | The current battery state of the device. | 0.1.0 |

LowPowerModeChangeEvent

| Prop | Type | Description | Since | | ------------- | -------------------- | ------------------------------------------------ | ----- | | enabled | boolean | Whether the low power mode is currently enabled. | 0.1.0 |

Type Aliases

BatteryState

The battery state of the device.

  • charging: The device is plugged into power and the battery is charging.
  • full: The device is plugged into power and the battery is fully charged.
  • unplugged: The device is not plugged into power and the battery is discharging.
  • unknown: The battery state could not be determined.

'charging' | 'full' | 'unplugged' | 'unknown'

Battery Information

Keep the following platform differences in mind when accessing battery information:

  • Android: The battery level and state are read from the sticky ACTION_BATTERY_CHANGED broadcast. The low power mode reflects the power saver mode of the device.
  • iOS: The battery level is not available on the iOS Simulator, so getBatteryLevel() rejects with an error there. Use a real device to test this method. The low power mode reflects the Low Power Mode of the device.
  • Web: The battery level and state are only available in browsers that implement the Battery Status API (Chromium-based browsers). The low power mode is not available on the Web.

FAQ

How is this plugin different from other similar plugins?

It reports the full battery picture — level, charging state, and low power mode — plus change events that observe the device only while a listener is attached, all through a fully typed API that works across Android, iOS, and supported browsers on the Web. If you just need a one-off battery reading, that's a quick call; if you want to react to charging and low-power changes over time without wasting energy, this plugin is built for exactly that.

Why does getBatteryLevel fail on the iOS Simulator?

The battery level is not available on the iOS Simulator, so getBatteryLevel() rejects with an error there. Use a real device to test this method.

Does this plugin work in all browsers?

No, on the Web the battery level and state are only available in browsers that implement the Battery Status API, which are Chromium-based browsers. The low power mode is not available on the Web at all.

What is the range of the battery level value?

The battery level is returned as a value between 0.0 and 1.0, where 0.0 means the battery is empty and 1.0 means it is fully charged. Multiply the value by 100 if you want to display it as a percentage.

What does low power mode mean on Android and iOS?

On Android, it refers to the power saver mode of the device. On iOS, it refers to the Low Power Mode. The isLowPowerModeEnabled() method and the lowPowerModeChange event are only available on Android and iOS.

Does listening for battery changes drain the battery?

The device is only observed while at least one listener is attached. As soon as you remove all listeners, for example with removeAllListeners(), the plugin stops observing the device.

Can I use this plugin with Ionic, React, Vue or Angular?

Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.

Related Plugins

  • Android Battery Optimization: Manage battery optimization settings and request exemptions on Android.
  • Device Info: Read device information, such as the model, manufacturer, operating system, and memory.
  • Thermal State: Read the device thermal state and react before the operating system throttles your app.

Newsletter

Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.

Changelog

See CHANGELOG.md.

License

See LICENSE.