Skip to content

zAlweNy26/capacitor-battery

Repository files navigation

Capacitor Plugin - Battery

Get access to every info about the device battery!

Supported Android version: 21+
Supported iOS version: Not supported
Supported Browsers: Chromium-based

Install

npm install @danyalwe/capacitor-battery
npx cap sync

Todos

  • Add support for iOS

Supported methods

Name Android iOS Web
start
stop
addListener
removeAllListeners

Supported properties

Property Android iOS Web
currentCapacity
totalCapacity
realPercentage
technology
temperature
voltage
amperage
wattage
health
status
chargeMode
level
hasBattery
isCharging
chargingTime
dischargingTime

API

Represents the BatteryPlugin interface.

start()

start() => Promise<BatteryInfos | undefined>

Starts the battery plugin and returns the battery information.

Returns: Promise<BatteryInfos>


stop()

stop() => Promise<void>

Stops the battery plugin.


addListener('batteryChange', ...)

addListener(eventName: 'batteryChange', listenerFunc: (event: BatteryInfos) => void) => Promise<PluginListenerHandle>

Adds a listener for the 'batteryChange' event.

Param Type Description
eventName 'batteryChange' The name of the event.
listenerFunc (event: BatteryInfos) => void The listener function to be called when the event is triggered.

Returns: Promise<PluginListenerHandle>


removeAllListeners()

removeAllListeners() => Promise<void>

Removes all listeners for the 'batteryChange' event.


Interfaces

BatteryInfos

Represents the battery information of the device.

Prop Type Description
level number The current battery level as a percentage (0-100).
hasBattery boolean Whether the device has a battery or not.
isCharging boolean Whether the device is currently charging or not.
chargingTime number The estimated time remaining until the battery is fully charged (in minutes). Only available when charging.
dischargingTime number The estimated time remaining until the battery is fully discharged (in minutes). Only available when discharging.
currentCapacity number The current battery capacity (in mAh). Only available on some devices.
totalCapacity number The total battery capacity (in mAh). Only available on some devices.
realPercentage number The real battery percentage, which may differ from the reported percentage. Only available on some devices.
technology string The technology used in the battery. Only available on some devices.
temperature number The current temperature of the battery (in Celsius). Only available on some devices.
voltage number The current voltage of the battery (in volts). Only available on some devices.
amperage number The current amperage of the battery (in amperes). Only available on some devices.
wattage number The current wattage of the battery (in watts). Only available on some devices.
health BatteryHealth The health status of the battery. Only available on some devices.
status BatteryStatus The status of the battery. Only available on some devices.
chargeMode BatteryChargeMode The charging mode of the battery. Only available on some devices.

PluginListenerHandle

Prop Type
remove () => Promise<void>

Enums

BatteryHealth

Members Description
UNKNOWN The health status is unknown.
COLD The battery is cold.
DEAD The battery is dead.
GOOD The battery is in good health.
OVERHEAT The battery is overheating.
OVER_VOLTAGE The battery is experiencing over voltage.
FAILURE The battery has failed.

BatteryStatus

Members Description
UNKNOWN The battery status is unknown.
NOT_CHARGING The battery is not charging.
DISCHARGING The battery is discharging.
CHARGING The battery is charging.
FULL The battery is full.

BatteryChargeMode

Members Description
UNKNOWN The charging mode is unknown.
AC The battery is being charged through an AC power source.
USB The battery is being charged through a USB connection.
DOCK The battery is being charged through a docking station.
WIRELESS The battery is being charged wirelessly.