# HTML5 Battery API

W3C have recently [\[ 28th August 2014\]](http://www.w3.org/TR/battery-status/) introduced  Battery API which is compatible with browsers. Previously Mozilla had [Battery API](https://developer.mozilla.org/en-US/docs/Web/API/Navigator.battery) 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](/assets/ed429-chrome.jpeg "Chrome Extension Battery API")](http://technorulerin.files.wordpress.com/2014/11/ed429-chrome.jpeg)

Chrome Extension Battery API

[![Firefox Battery API](/assets/274d1-firefox.png "Firefox Battery API")](http://technorulerin.files.wordpress.com/2014/11/274d1-firefox.png)

Firefox Battery API

You can also download the source code from [Github](https://github.com/viswaprasath/Apps/tree/master/Battery%20app) and try in your local machine.
