Battery Battery Battery Battery Class

Definition

Provides information about a battery controller that is currently connected to the device. For more info, see Get battery information.

public : sealed class Battery : IBatterypublic sealed class Battery : IBatteryPublic NotInheritable Class Battery Implements IBattery// You can use this class in JavaScript.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

In this context, device refers to the hardware that your app is running on. Battery controller refers to the electronics that interface between the physical battery and the operating system. A battery controller appears in Device Manager as a "Battery" under the Batteries node.

Depending on the device, it may be possible to remove the physical battery while the device remains running. For example, a laptop that's plugged into A/C power. In that case, if the battery controller were part of the laptop enclosure, you could potentially create a Battery object when no battery is connected to the device. However, if the battery controller resided on the physical battery, it would no longer be visible to the operating system and therefore you could not create a corresponding Battery object for an individual battery.

Properties

AggregateBattery AggregateBattery AggregateBattery AggregateBattery

Gets a Battery object that represents all battery controllers connected to the device.

public : static Battery AggregateBattery { get; }public static Battery AggregateBattery { get; }Public Static ReadOnly Property AggregateBattery As Battery// You can use this property in JavaScript.
Value
Battery Battery Battery Battery

A Battery object that represents overall battery power.

Remarks

When created with AggregateBattery, the Battery object represents an aggregate of all battery controllers connected to the device.

See Also

DeviceId DeviceId DeviceId DeviceId

Gets the identifier (ID) for an individual battery controller.

public : PlatForm::String DeviceId { get; }public string DeviceId { get; }Public ReadOnly Property DeviceId As string// You can use this property in JavaScript.
Value
PlatForm::String string string string

The battery controller identifier (ID).

Remarks

When the Battery object represents an individual battery controller, this property value can be used with the FromIdAsync method to re-create an object that represents the same battery controller (if it's still connected to the device). When the Battery object is an aggregate of battery controllers, this property is equal to "AggregateBattery ".

See Also

Methods

FromIdAsync(String) FromIdAsync(String) FromIdAsync(String) FromIdAsync(String)

Gets a Battery object that represents an individual battery controller connected to the device.

public : static IAsyncOperation<Battery> FromIdAsync(PlatForm::String deviceId)public static IAsyncOperation<Battery> FromIdAsync(String deviceId)Public Static Function FromIdAsync(deviceId As String) As IAsyncOperation( Of Battery )// You can use this method in JavaScript.
Parameters
deviceId
PlatForm::String String String String

The device ID of the battery controller (DeviceId ).

Returns

A Battery object that corresponds to the specified battery controller.

Remarks

FromIdAsync will return null if the battery controller does not exist and the deviceId value is well-formed. If the deviceId value is not well-formed, such as "AggregateBattery," then the method will fail with STATUS_OBJECT_NAME_INVALID.

You can use a DeviceInformation object for a battery controller to use that object's Id property value as the deviceId parameter in FromIdAsync to create a Battery object

See Also

GetDeviceSelector() GetDeviceSelector() GetDeviceSelector() GetDeviceSelector()

Gets an Advanced Query Syntax (AQS) string that can be used to find all battery controllers that are connected to the device.

public : static PlatForm::String GetDeviceSelector()public static string GetDeviceSelector()Public Static Function GetDeviceSelector() As string// You can use this method in JavaScript.
Returns
PlatForm::String string string string

An AQS string that can be used to find all battery controllers connected to the device.

Remarks

Use the AQS string returned by GetDeviceSelector with the DeviceInformation APIs to find all battery controllers that are connected to the device. See FromIdAsync for information on how to create a Battery object.

See Also

GetReport() GetReport() GetReport() GetReport()

Gets a BatteryReport object that indicates the charge, capacity, and status of the battery or aggregate.

public : BatteryReport GetReport()public BatteryReport GetReport()Public Function GetReport() As BatteryReport// You can use this method in JavaScript.
Returns

Indicates the charge, capacity, and status of the battery or aggregate.

See Also

Events

ReportUpdated ReportUpdated ReportUpdated ReportUpdated

Occurs when the charge, capacity, or status of a battery changes.

public : event TypedEventHandler ReportUpdated<Battery,  object>public event TypedEventHandler ReportUpdated<Battery,  object>Public Event ReportUpdated<Battery,  object>// You can use this event in JavaScript.

Remarks

The ReportUpdated event is triggered by any change in status, charge rate, or power capacity on any of the batteries connected to the device. This typically happens immediately for status changes and periodically for all other changes.

See Also

See Also