Search code examples
ionic-frameworkpluginsionic4

Having issue with Battery status in Ionic 4


I'm using Ionic4 and I'm trying to get the device battery level. But I get an error: ERROR TypeError: Invalid event target and for the battery level, I get undefined.

Has anyone run into the same problem


Solution

  • This is how I managed to get the battery status in Ionic 4:

    window.addEventListener('batterystatus', this.onBatteryStatus, false);
    
    onBatteryStatus(status) {
    console.log('Level: ' + status.level + ' isPlugged: ' + status.isPlugged);
    }