Battery


Purpose

This API enables creating applications that can monitor the battery level and charging state of a device. It allows you to observe battery state changes and to get information about the battery's current state. You can only receive observable events if the device allows access to the data.

Use the launchbox.Battery reference to obtain an instance of the Battery object.

Module

This object belongs to the Battery product module.

Properties

Properties of the Battery object are listed below:

Name Description Type
onLevelLow

An observable event that notifies the web app about low level state changes. To start receiving events, you must call the startLowLevelMonitoring method. On Android, this event is sent in response to system notifications. On iOS, it is sent when the battery level falls under 15 percent or is under 15 percent and an external source of power has been disconnected.

event
onLevelOkay

An observable event that notifies the web app about low level state changes. To start receiving events, you must call the startLowLevelMonitoring method. On Android, this event is sent in response to system notifications. On iOS, it is sent when the battery level goes over 20 percent and the onLevelLow event occurred previously.

event
onPowerConnected An observable event that notifies the web app that a power source has been connected. To start receiving events, you must call the startPowerConnectionMonitoring method. event
onPowerDisconnected An observable event that notifies the web app that a power source has been disconnected. To start receiving events, you must call the startPowerConnectionMonitoring method. event

Constants

The table below lists all constants of the Battery object that are used as failure codes.

Name Description
launchbox.Battery.InformationUnavailableError Denotes that battery level or power connection information is not available.
launchbox.Battery.InternalError Denotes that it is impossible to start or stop battery monitoring.

Methods

Name Return type Description
getLevel promise

Provides access to the current battery level.

isPowerConnected promise

Checks whether the power source is connected.

startLowLevelMonitoring promise

Starts low power level state monitoring. Initiates delivery of onLevelLow and onLevelOkay observable events.

stopLowLevelMonitoring promise

Stops low power level state monitoring. As a result, the onLevelLow and onLevelOkay observable events are no longer delivered.

startPowerConnectionMonitoring promise

Starts power connection state monitoring. Initiates delivery of onPowerConnected and onPowerDisconnected observable events.

stopPowerConnectionMonitoring promise

Stops power connection state monitoring. As a result, the onPowerConnected and onPowerDisconnected observable events are no longer delivered.

Related topics

Public API reference
Legal notice | Copyright © 2016 and Confidential to Pegasystems Inc. All rights reserved
PDN | Hybrid Container | Feedback
Advanced...