Access API: Battery Events

Added in version 9.2

This JavaScript API allows you to check the current status of the battery and returns callbacks when charging status or battery levels change.

Functions

Callbacks

Requirements

  • Access JavaScript API
    • 'By Import' - recommended, works both online & offline, requires inclusion of kiosk_functions.js prior to any of the following calls.
    • 'By Injection' - only works offline, may not be available 'onload' event.

Sample Code

This sample code relies on the JavaScript APIs built into Kiosk Pro and will not run successfully in other browsers or within our in-app help interface.  
To run sample code, set the app's homepage to http://www.kioskproapp.com/battery

Download Sample Code


kp_Battery_requestInfo

This function returns a callback detailing the current charging status of the device and the battery level.

Format
kp_Battery_requestInfo(callback);
		
Parameters callback = callback name as string
Callback format
callback(batteryStatus, batteryLevel);
		
Callback return values
  • batteryStatus - [integer] current charging status of the device. Possible options include:
    • 0 - unknown, battery state for the device cannot be determined.
    • 1 - battery is discharging.
    • 2 - battery is charging, but under 100%.
    • 3 - battery is full.
  • batteryLevel - [float] current battery level of the device. Battery level ranges from 0.0 (fully discharged) to 1.0 (100% charged). If battery monitoring is not enabled or cannot be determined, the value of this property is –1.0.


kp_Battery_statusDidChange

This callback is triggered when the audio output has changed. For example, when headphones are plugged into the device.

Format
kp_Battery_statusDidChange(batteryStatus);
		
Return values

batteryStatus - [integer] current charging status of the device. Possible options include:

  • 0 - unknown, battery state for the device cannot be determined.
  • 1 - battery is discharging.
  • 2 - battery is charging, but under 100%.
  • 3 - battery is full.


kp_Battery_levelDidChange

This callback is triggered when the audio output has changed. For example, when headphones are plugged into the device.

Format
kp_Battery_levelDidChange(batteryLevel);
		
Return values

batteryLevel - [float] current battery level of the device. Battery level ranges from 0.0 (fully discharged) to 1.0 (100% charged). If battery monitoring is not enabled or cannot be determined, the value of this property is –1.0.

Still stuck? How can we help? How can we help?