DeviceData.BatteryMonitoringEnabled

From Xojo Documentation

Property (As Boolean )
aDeviceData.BatteryMonitoringEnabled = newBooleanValue
or
BooleanValue = aDeviceData.BatteryMonitoringEnabled

New in 2020r2

Supported for all project types and targets.

If True, the BatteryLevel and BatteryState will be updated.

Notes

To preserve battery, set this property to True only while you need to have up to date battery information then set it back to False.

Sample Code

This example enables monitoring of the battery, gets the current battery level, disables battery monitoring and then displays the level in a message box:

System.Device.BatteryMonitoringEnabled = True
Var batteryPercentage As Integer = System.Device.BatteryLevel * 100
System.Device.BatteryMonitoringEnabled = False
MessageBox("Your battery is at " + batteryLevel.ToString + "%")

See Also

BatteryLevel and BatteryState properties.