Device.getBatteryPercent()

Overview

Gets the percent of the battery remaining, if supported.

Added in version 2.1.11

Format

var percentRemaining = Device.getBatteryPercent();

Parameter Description Type Required Notes
percentRemaining A number representing the percent of battery remaining. Integer Return Normal value between 0 - 100. May return -1 or 255 if the battery level cannot be determined.

Example

Copy
/* Display a toast message of the device's remaining battery.
 */
var percentRemaining = Device.getBatteryPercent();
if(percentRemaining >= 0) {
    View.toast('Battery at ' + percentRemaining + '%', true);
}