The 2017 Ionic Developer Survey Results are in!

Battery Status

Improve this doc

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

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-battery-status
    $ npm install --save @ionic-native/battery-status
    
  2. Add this plugin to your app's module

Supported platforms

Usage

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 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 critial

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

API

Native

General