Battery
Pre-requisite: The user has to be signed in to perform the following operations.
Is this a battery camera
A camera’s power source decides how it behaves when idle and how carefully the app should use it:
if (device.hasBattery()) {
// show the battery indicator
}
hasBattery() is true for PowerSource.Battery and PowerSource.ACAndBattery — a camera that can run on mains but has a battery to fall back on still counts. PowerSource.AC is the only value that does not.
device.isLowResourceDevice() is the broader check: true for battery cameras and 4G cameras, the two cases where an unattended stream costs the user something. It is a helper for the app; the SDK does not branch on it.
Reading the level
The charge level and charging state live on the device record:
val percentage = device.deviceState.batteryPercentage
val isCharging = device.deviceState.charging
batteryPercentage is an Int; charging is a nullable Boolean, so treat null as unknown rather than as “not charging”.
These are a snapshot taken when the device record was fetched, not a live flow. Nothing pushes an updated level while a stream is running, so refresh them by re-fetching the camera — see Device Retrieval and Information.
Sleep
An idle battery camera reports DeviceStatus.SLEEP rather than OFFLINE. A sleeping camera is reachable; an offline one is not, so do not treat the two the same when deciding whether to offer live view.
The SDK wakes a sleeping camera for you rather than making the app do it. Whether a camera needs waking is decided by device.isMcuSupported, not by its power source:
| Action | What wakes the camera |
|---|---|
| Live view, SD card playback | Creating the LiveStreamClient / SDCardPlaybackClient, when isMcuSupported |
| Settings writes, PTZ, firmware, delete, lullaby | Every DeviceService / HubService write that takes a Device, when isMcuSupported |
| Two-way call | initiateVideoCall / updateVideoCallStatus, before the request is sent |
| Keeping a stream awake | LiveStreamClient.keepAwake() (when isMcuSupported); SDCardPlaybackClient.keepAlive() (when device.hasBattery()) |
Reads (getDevice, getDeviceSetting, getDeviceCluster, getCloudSettings, …) never wake the camera. A write to a sleeping camera polls the device until it reports ONLINE or OFFLINE, then sends the request, so expect the callback to take a few seconds. If the camera stays asleep the SDK keeps re-sending the wake request; onError fires only when a request itself fails, so put your own timeout around the call if the UI needs one.
Not draining it
A stream nobody is watching keeps the radio and sensor awake. Set autoDisconnectAfter when creating the client so an unattended stream ends on its own, and use disableAutoDisconnect() / enableAutoDisconnect() to pause the timer only while the user is actively interacting.
See Live View for the client options and Trail for cameras where the cellular data pool drains alongside the battery.