Last active
December 2, 2017 23:49
-
-
Save osbulbul/8549a9c3796928f0b20d6f9316b72dcd to your computer and use it in GitHub Desktop.
BatteryManager Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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