Skip to main content
Version: v2

Battery

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

Battery Sensor.

Methods​

getCurrent​

Get the current device power percentage, range 0 - 100

getCurrent(): number

onChange​

Register the power change event callback function

onChange(callback: () => void): void

offChange​

Cancel the power change event callback function

offChange(callback: () => void): void

Example​

import { Battery } from '@zos/sensor'

const battery = new Battery()
const current = battery.getCurrent()

const callback = () => {
console.log(battery.getCurrent())
}

battery.onChange(callback)

// When not needed for use
battery.offChange(callback)