Ionic Battery Status– This plugin is basically used to deal with device’s battery such as getting battery status on low, on change or on critical. Here in this tutorial, we are going to explain how to use this plugin to get the status.
Ionic Battery Status Native Plugin Example
You can install the cordova plugin cordova-plugin-battery-status simply as below-
Installation
Ionic Battery Status Install Plugin:
$ ionic cordova plugin add cordova-plugin-battery-status
$ npm install --save @ionic-native/battery-status
|
- Windows Phone 8
- Amazon Fire OS
- Android
- BlackBerry 10
- Browser
- Firefox OS
- iOS
- Tizen
- Ubuntu
- Windows
Example
Ionic Battery Status Native Plugin Example:
import { BatteryStatus } from '@ionic-native/battery-status';
constructor(private batteryStatus: BatteryStatus) { }
...
// watch change in battery status
let subscription = this.batteryStatus.onChange().subscribe(
(status: BatteryStatusResponse) => {
console.log(status.level, status.isPlugged);
}
);
// stop watch
subscription.unsubscribe();
|
Instance Members
- onChange()– Watch when battery level change.
- onLow()– Watch when battery low.
- onCritical()– Watch when Battery Critical.
Battery Status Response
Param |
Details |
level(number) |
The battery Charge Percentage. |
isPlugged(boolean) |
Return true if charger is plugged in. |