openharmony 鸿蒙 capi-ohbattery-info-h

2026-08-25 浏览 (1)

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

Nametypedef KeywordDescription
BatteryInfo_BatteryPluggedTypeBatteryInfo_BatteryPluggedTypeEnumerates the battery plugged types.

Functions

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

Variables

NameDescription
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 ItemDescription
PLUGGED_TYPE_NONE = 0No power supply.
PLUGGED_TYPE_AC = 1AC charging.
PLUGGED_TYPE_USB = 2USB DC charging.
PLUGGED_TYPE_WIRELESS = 3Wireless charging.
PLUGGED_TYPE_BUTT = 4Reserved.

Function Description

OH_BatteryInfo_GetCapacity()

int32_t OH_BatteryInfo_GetCapacity()

Description

Obtains the current battery capacity, in percentage.

System capability: SystemCapability.PowerManager.BatteryManager.Core

Since: 13

Returns

TypeDescription
int32_tA 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

TypeDescription
BatteryInfo_BatteryPluggedTypeReturns 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.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 errorcode-zlib

openharmony 鸿蒙 capi-oh-scan-scan-picturescanprogress

openharmony 鸿蒙 js-apis-screen-lock

openharmony 鸿蒙 capi-os-account-common-h

openharmony 鸿蒙 js-apis-screen-lock-sys

openharmony 鸿蒙 capi-oh-print-print-propertylist

openharmony 鸿蒙 capi-oh-scan

openharmony 鸿蒙 js-apis-system-device

openharmony 鸿蒙 errorcode-intelligentVoice

openharmony 鸿蒙 js-apis-request-sys

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/gOafSeV8