BatteryManager Class

The battery status of the device (https://w3c.github.io/battery/#the-batterymanager-interface), returned by Navigator.GetBattery: it is read from the BatteryStatusProvider of the browsing context (BatteryStatusOptions.Provider), and fires the chargingchange, chargingtimechange, dischargingtimechange and levelchange events when it changes, while its document is visible.

public sealed class BatteryManager : EventTarget
Inheritance
EventTarget BatteryManager

Properties

NameDescription
ChargingGets whether the battery is charging (or there is no battery).
ChargingTimeGets the remaining time in seconds until the battery is fully charged (0 when it is full), or positive infinity.
DischargingTimeGets the remaining time in seconds until the battery is depleted, or positive infinity.
LevelGets the level of the battery, between 0 and 1, rounded to two decimals.
OnChargingChangeGets or sets the event handler of the chargingchange event.
OnChargingTimeChangeGets or sets the event handler of the chargingtimechange event.
OnDischargingTimeChangeGets or sets the event handler of the dischargingtimechange event.
OnLevelChangeGets or sets the event handler of the levelchange event.

Gets whether the battery is charging (or there is no battery).

public bool Charging { get; }

ChargingTime

BatteryStatus.cs

Gets the remaining time in seconds until the battery is fully charged (0 when it is full), or positive infinity.

public double ChargingTime { get; }

DischargingTime

BatteryStatus.cs

Gets the remaining time in seconds until the battery is depleted, or positive infinity.

public double DischargingTime { get; }

Gets the level of the battery, between 0 and 1, rounded to two decimals.

public double Level { get; }

OnChargingChange

BatteryStatus.cs

Gets or sets the event handler of the chargingchange event.

public Action<Event>? OnChargingChange { get; set; }

OnChargingTimeChange

BatteryStatus.cs

Gets or sets the event handler of the chargingtimechange event.

public Action<Event>? OnChargingTimeChange { get; set; }

OnDischargingTimeChange

BatteryStatus.cs

Gets or sets the event handler of the dischargingtimechange event.

public Action<Event>? OnDischargingTimeChange { get; set; }

OnLevelChange

BatteryStatus.cs

Gets or sets the event handler of the levelchange event.

public Action<Event>? OnLevelChange { get; set; }