mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 11:17:19 +08:00
Battery comments
This commit is contained in:
@ -2,6 +2,18 @@ import * as util from 'ionic/util';
|
||||
|
||||
import {NativePlugin} from '../plugin';
|
||||
|
||||
/**
|
||||
* Track battery status. Uses the HTMl5 Battery API if available or
|
||||
* the `cordova-plugin-battery-status` plugin.
|
||||
*
|
||||
* @usage
|
||||
*
|
||||
* ```js
|
||||
* Battery.getStatus().then((data) => {
|
||||
* console.log(data.charging, data.level, data.chargingTime, data.dischargingTime)
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
@NativePlugin({
|
||||
name: 'Battery',
|
||||
platforms: ['ios', 'android', 'web'],
|
||||
@ -10,6 +22,15 @@ import {NativePlugin} from '../plugin';
|
||||
}
|
||||
})
|
||||
export class Battery {
|
||||
|
||||
/**
|
||||
* Get the status of the battery. Data is of the format:
|
||||
* { charging, level, chargingTime, dischargingTime }
|
||||
*
|
||||
* Note: certain fields might not be available depending on the platform.
|
||||
*
|
||||
* @return {object} battery status
|
||||
*/
|
||||
static getStatus() {
|
||||
return new Promise((resolve, reject) => {
|
||||
if(navigator.getBattery) {
|
||||
|
Reference in New Issue
Block a user