Battery Status
Requires Cordova plugin: cordova-plugin-batterystatus. For more info, please see the BatteryStatus plugin docs.
Repo: https://github.com/apache/cordova-plugin-battery-status
Installation
- Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add cordova-plugin-battery-status $ npm install --save @ionic-native/battery-status@4
- Add this plugin to your app's module
Supported platforms
- iOS
- Android
- Windows
- Browser
Usage
import { BatteryStatus } from '@ionic-native/battery-status';
constructor(private batteryStatus: BatteryStatus) { }
...
// watch change in battery status
const subscription = this.batteryStatus.onChange().subscribe(status => {
console.log(status.level, status.isPlugged);
});
// stop watch
subscription.unsubscribe();
Instance Members
onChange()
Watch the change in battery level
Returns: Observable<BatteryStatusResponse>
Returns an observable that pushes a status object
onLow()
Watch when the battery level goes low
Returns: Observable<BatteryStatusResponse>
Returns an observable that pushes a status object
onCritical()
Watch when the battery level goes to critical
Returns: Observable<BatteryStatusResponse>
Returns an observable that pushes a status object
BatteryStatusResponse
Param | Type | Details |
---|---|---|
level |
number
|
The battery charge percentage |
isPlugged |
boolean
|
A boolean that indicates whether the device is plugged in |