Mobile Web Wearable Web

Battery Status

You can programmatically determine the battery status of the device on which your application is running.

Knowing the battery status of the device helps you to defer or scale back work when the device is not charging or is low on battery. For example:

  • A Web-based email client can modify how often it checks the server for new email based on the battery status. It can make the check very few seconds if the device is charging or has a full battery, but less often if the device is not charging or is low on battery.
  • A Web-based word processor can monitor the battery level and prevent data loss by saving any changes before the battery runs out.

The main features of the Battery Status API include:

  • Retrieving the battery status

    You can use the charging, chargingTime, dischargingTime, and level attributes of the BatteryManager interface to check the battery status information, such as battery charging status, remaining charging time (until fully charged), remaining battery life (until battery is empty), and battery level.

  • Detecting battery status changes

    You can set event listeners with the BatteryManager interface attributes to detect changes in the battery status.

Go to top