Tutorial by Examples

// Get the battery API navigator.getBattery().then(function(battery) { // Battery level is between 0 and 1, so we multiply it by 100 to get in percents console.log("Battery level: " + battery.level * 100 + "%"); });
// Get the battery API navigator.getBattery().then(function(battery) { if (battery.charging) { console.log("Battery is charging"); } else { console.log("Battery is discharging"); } });
// Get the battery API navigator.getBattery().then(function(battery) { console.log( "Battery will drain in ", battery.dischargingTime, " seconds" ); });
// Get the battery API navigator.getBattery().then(function(battery) { console.log( "Battery will get fully charged in ", battery.chargingTime, " seconds" ); });
// Get the battery API navigator.getBattery().then(function(battery) { battery.addEventListener('chargingchange', function(){ console.log( 'New charging state: ', battery.charging ); }); battery.addEventListener('levelchange', function(){ console.log( 'New battery...

Page 1 of 1