Skip to content

Instantly share code, notes, and snippets.

@osbulbul
Last active December 2, 2017 23:49
Show Gist options
  • Save osbulbul/8549a9c3796928f0b20d6f9316b72dcd to your computer and use it in GitHub Desktop.
Save osbulbul/8549a9c3796928f0b20d6f9316b72dcd to your computer and use it in GitHub Desktop.
BatteryManager Example
navigator.getBattery().then(function(battery){
function currentBatteryInfo(){
console.log("Battery charging: "+battery.charging);
console.log("Remaining time to fully charge: "+battery.chargingTime);
console.log("Remaining time to discharge: "+battery.dischargingTime);
console.log("Battery level: "+battery.level*100+"%");
}
currentBatteryInfo();
battery.addEventListener('chargingchange', function(){
console.log("Battery charging status changed: "+(battery.charging ? "Charging..." : "No Charging"));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment