21st Mar 2018, 10:52 PM
Sina
Sina - avatar
4 Answers
+ 1
The battery property has been removed in favor of the standard Navigator.getBattery() method, which returns a battery Promise. Its support is still partial though. Given that, you can run the code like this: navigator.getBattery().then(function(battery){ alert('Battery: ' + battery.level * 100 + '%'); if(battery.charging) {    alert('Battery Status: Charging'); } else {   alert('Battery Status: Power cable not connected.'); } }); Hope this helps.
22nd Mar 2018, 12:02 AM
Ulisses Cruz
Ulisses Cruz - avatar
0
it helps me but I want to write it without ".then"
22nd Mar 2018, 12:00 PM
Sina
Sina - avatar
0
See my code again I changed it but it shows battery level Nan
22nd Mar 2018, 12:01 PM
Sina
Sina - avatar
0
Can you write it without .then ??
22nd Mar 2018, 12:04 PM
Sina
Sina - avatar