Battery API

The Battery API provides a standard interface that can be used across multiple hardware platforms for checking the current state of a device's battery. It enables your app to register/ unregister for the battery monitoring service of the device operating system and check the battery level on the customer's device.

The Battery API uses kony.os namespace and the following API elements.

Function Description
kony.os.getBatteryLevel

Retrieves the current percentage charge level of the device battery, as an integer value.

kony.os.getBatteryState Retrieves the current state of the battery.
kony.os.registerBatteryService Registers for the battery monitoring service of the device operating system.
kony.os.unregisterBatteryService Stops the monitoring process of the device battery.
 

To register for the battery monitoring service of the device operating system, invoke the kony.os.registerBatteryService function. The callback is delivered to the most recent registered battery service. If you want to stop the monitoring process of the device battery, use the kony.os.unregisterBatteryService function. You must call this API when the use of the battery monitoring service has been completed, to reduce the overhead.

To check the current battery level, use the kony.os.getBatteryLevel function. To see whether the battery is charging, discharging, and so forth, invoke the kony.os.getBatteryState function.

To view the functionality of the Battery API in action, download the sample application from the link below. Once the application is downloaded, build and preview the application using the Quantum App.