Class Battery

Definition

Namespace:
Tizen.System
Assembly:
Tizen.System.dll

The Battery class provides the properties and events for the device battery.

C#
Copy
public static class Battery
Inheritance
object
Battery
Remarks

The Battery API provides the way to get the current battery capacity value (Percent), the battery state, and the charging state. It also provides the events for an application to receive the battery status change events from the device. To receive the battery event, the application should register with the respective EventHandler.

Properties

View Source

IsCharging

Gets the current device's charging state which the battery is charging.

Declaration
C#
Copy
public static bool IsCharging { get; }
Property Value
Type Description
bool
Remarks

Checks whether the battery is currently being charged or not.

Examples
Copy
using Tizen.System; bool charging = Battery.IsCharging; ...
View Source

Level

Declaration
C#
Copy
public static BatteryLevelStatus Level { get; }
Property Value
Type Description
BatteryLevelStatus
Remarks

The Battery API provides the way to get the current battery capacity value (Percent), the battery state, and the charging state. It also provides the events for an application to receive the battery status change events from the device. To receive the battery event, the application should register with the respective EventHandler.

View Source

Percent

Gets the current device's invalid battery charge percentage as an interger value.

Declaration
C#
Copy
public static int Percent { get; }
Property Value
Type Description
int

It returns an integer value from 0 to 100 that indicates the remaining battery charge as a percentage of the maximum level.

Remarks

It returns an integer value from 0 to 100 that indicates remaining battery charge as a percentage of the maximum level.

Examples
Copy
Console.WriteLine("battery Percent is: {0}", Tizen.System.Battery.Percent);
View Source

PowerSource

Gets the current device's power source information from the battery.

Declaration
C#
Copy
public static BatteryPowerSource PowerSource { get; }
Property Value
Type Description
BatteryPowerSource

The battery power source type.

Remarks

Retrieves the current battery power source information (e.g., ac, usb, etc).

Examples
Copy
using Tizen.System; ... BatteryPowerSource PowerSourceType = Battery.PowerSource; if (PowerSourceType == BatteryPowerSource.None) ... ...

Events

View Source

ChargingStateChanged

ChargingStatusChanged is triggered when the battery charging status is changed. This event is triggered when the charger is connected/disconnected.

Declaration
C#
Copy
public static event EventHandler<BatteryChargingStateChangedEventArgs> ChargingStateChanged
Event Type
Type Description
System.EventHandler<TEventArgs><BatteryChargingStateChangedEventArgs>
Remarks

The Battery API provides the way to get the current battery capacity value (Percent), the battery state, and the charging state. It also provides the events for an application to receive the battery status change events from the device. To receive the battery event, the application should register with the respective EventHandler.

Examples
Copy
public static async Task BatteryEventHandler() { EventHandler<BatteryChargingStateChangedEventArgs> handler = null; handler = (object sender, BatteryChargingStateChangedEventArgs args) => { Console.WriteLine("battery Level is: {0}", args.IsCharging); } Battery.ChargingStateChanged += handler; await Task.Delay(20000); }
View Source

LevelChanged

LevelChanged is triggered when the battery level is changed.

Declaration
C#
Copy
public static event EventHandler<BatteryLevelChangedEventArgs> LevelChanged
Event Type
Type Description
System.EventHandler<TEventArgs><BatteryLevelChangedEventArgs>
Remarks

The Battery API provides the way to get the current battery capacity value (Percent), the battery state, and the charging state. It also provides the events for an application to receive the battery status change events from the device. To receive the battery event, the application should register with the respective EventHandler.

Examples
Copy
public static async Task BatteryEventHandler() { EventHandler<BatteryLevelChangedEventArgs> handler = null; handler = (object sender, BatteryLevelChangedEventArgs args) => { Console.WriteLine("battery Level is: {0}", args.Level); } Battery.LevelChanged += handler; await Task.Delay(20000); }
View Source

PercentChanged

CapacityChanged is triggered when the battery charge percentage is changed.

Declaration
C#
Copy
public static event EventHandler<BatteryPercentChangedEventArgs> PercentChanged
Event Type
Type Description
System.EventHandler<TEventArgs><BatteryPercentChangedEventArgs>
Remarks

The Battery API provides the way to get the current battery capacity value (Percent), the battery state, and the charging state. It also provides the events for an application to receive the battery status change events from the device. To receive the battery event, the application should register with the respective EventHandler.

Examples
Copy
public static async Task BatteryEventHandler() { EventHandler<BatteryPercentChangedEventArgs> handler = null; handler = (object sender, BatteryChargingStateChangedEventArgs args) => { Console.WriteLine("battery Percent is: {0}", args.Percent); } Battery.PercentChanged += handler; await Task.Delay(20000); }