HTML5 Battery API

VISWAPRASATH
Techno rulers
Published in
2 min readMar 2, 2015

W3C have recently [ 28th August 2014] introduced Battery API which is compatible with browsers. Previously Mozilla had Battery API for their Firefox OS.

The aim of this experiment is to write a certain line of code so we can use in both Firefox OS and also as Chrome Extension.

Here we need several files

index.html app.js manifest.webapp for Firefox OS manifest.json for Chrome

I would like to explain only the API part

First we have to get whether it is Firefox environment or Chrome.

Then after that we can easily get the battery level, battery charging time, battery dis charging time and level of charge.

battery.charging is used to know whether we are charging. battery.level is used to know the current battery level. battery.dischargingTime is used to know how long it will take to discharge. battery.chargingTime is used to know how long it will take to charge.

Then you can easily load your app to Firefox OS and Chrome extension. The output will be displayed as below

Chrome Extension Battery API

Firefox Battery API

You can also download the source code from Github and try in your local machine.

Originally published at technorulerin.wordpress.com on November 27, 2014.

--

--