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.
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
|
event |
onLevelOkay |
An observable event that notifies the web app about low level state changes. To
start receiving events, you must call the
|
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 |
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. |
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 |
stopLowLevelMonitoring | promise |
Stops low power level state monitoring. As a result, the |
startPowerConnectionMonitoring | promise |
Starts power connection state monitoring. Initiates delivery of
|
stopPowerConnectionMonitoring | promise |
Stops power connection state monitoring. As a result, the |