ohbattery_info.h

Overview

Declares the battery APIs that are used to obtain the current battery capacity and power supply type and define common battery events.

Reference file: <BasicServicesKit/ohbattery_info.h>

Library: libohbattery_info.so

System capability: SystemCapability.PowerManager.BatteryManager.Core

Since: 13

Related modules: OH_BatteryInfo

Summary

Enums

Name typedef Keyword Description
BatteryInfo_BatteryPluggedType BatteryInfo_BatteryPluggedType Enumerates the battery plugged types.

Functions

Name Description
int32_t OH_BatteryInfo_GetCapacity() Obtains the current battery capacity.
BatteryInfo_BatteryPluggedType OH_BatteryInfo_GetPluggedType() Obtains the battery plugged type.

Variables

Name Description
static const char * COMMON_EVENT_KEY_CAPACITY = "soc" Defines the common event indicating a battery capacity change.
Since: 13
static const char * COMMON_EVENT_KEY_CHARGE_STATE = "chargeState" Defines the common event indicating a charging status change.
Since: 13
static const char * COMMON_EVENT_KEY_PLUGGED_TYPE = "pluggedType" Defines the common event indicating a battery plugged type change.
Since: 13

Enum Description

BatteryInfo_BatteryPluggedType

enum BatteryInfo_BatteryPluggedType

Description

Enumerates the battery plugged types.

Since: 13

Enum Item Description
PLUGGED_TYPE_NONE = 0 No power supply.
PLUGGED_TYPE_AC = 1 AC charging.
PLUGGED_TYPE_USB = 2 USB DC charging.
PLUGGED_TYPE_WIRELESS = 3 Wireless charging.
PLUGGED_TYPE_BUTT = 4 Reserved.

Function Description

OH_BatteryInfo_GetCapacity()

int32_t OH_BatteryInfo_GetCapacity()

Description

Obtains the current battery capacity.

System capability: SystemCapability.PowerManager.BatteryManager.Core

Since: 13

Returns

Type Description
int32_t A number in the range from 0 to 100.

OH_BatteryInfo_GetPluggedType()

BatteryInfo_BatteryPluggedType OH_BatteryInfo_GetPluggedType()

Description

Obtains the battery plugged type.

System capability: SystemCapability.PowerManager.BatteryManager.Core

Since: 13

Returns

Type Description
BatteryInfo_BatteryPluggedType Returns PLUGGED_TYPE_NONE if the power supply is removed;
returns PLUGGED_TYPE_AC if the power supply is in AC charging mode;
returns PLUGGED_TYPE_USB if the power supply is in USB DC charging mode;
returns PLUGGED_TYPE_WIRELESS if the power supply is in wireless charging mode;
returns PLUGGED_TYPE_BUTT if the battery plugged type is unknown.