1# OH_BatteryInfo
2
3## Overview
4
5Provides APIs for the BatteryInfo module to obtain battery information.
6
7**System capability**: SystemCapability.PowerManager.BatteryManager.Core
8
9**Since**: 13
10
11
12## Summary
13
14
15### File
16
17| Name| Description|
18| -------- | -------- |
19| [ohbattery_info.h](ohbattery__info_8h.md) | Declares the battery APIs that are used to obtain the current battery capacity and power supply type and define common battery events.<br>**Library**: libohbattery_info.so|
20
21
22### Enums
23
24| Name| Description|
25| -------- | -------- |
26| [BatteryInfo_BatteryPluggedType](#batteryinfo_batterypluggedtype) {<br>PLUGGED_TYPE_NONE , PLUGGED_TYPE_AC , PLUGGED_TYPE_USB , PLUGGED_TYPE_WIRELESS , PLUGGED_TYPE_BUTT } | Defines the plug type.|
27
28
29### Functions
30
31| Name| Description|
32| -------- | -------- |
33| int32_t [OH_BatteryInfo_GetCapacity](#oh_batteryinfo_getcapacity) () | Obtains the current battery capacity.|
34| [BatteryInfo_BatteryPluggedType](#batteryinfo_batterypluggedtype)[OH_BatteryInfo_GetPluggedType](#oh_batteryinfo_getpluggedtype) () | Obtains the plug type.|
35
36
37### Variables
38
39| Name| Description|
40| -------- | -------- |
41| static const char\* [COMMON_EVENT_KEY_CAPACITY](#common_event_key_capacity) = "soc" | Common event indicating a battery capacity change.|
42| static const char\* [COMMON_EVENT_KEY_CHARGE_STATE](#common_event_key_charge_state) = "chargeState" | Common event indicating a charging status change.|
43| static const char\* [COMMON_EVENT_KEY_PLUGGED_TYPE](#common_event_key_plugged_type) = "pluggedType" | Common event indicating a plug type change.|
44
45
46## Enum Description
47
48
49### BatteryInfo_BatteryPluggedType
50
51```
52enum BatteryInfo_BatteryPluggedType
53```
54
55**Description**
56
57Defines the plug type.
58
59**Since**: 13
60
61| Value| Description|
62| -------- | -------- |
63| PLUGGED_TYPE_NONE | No power supply.|
64| PLUGGED_TYPE_AC | AC charging.|
65| PLUGGED_TYPE_USB | USB DC charging.|
66| PLUGGED_TYPE_WIRELESS | Wireless charging.|
67| PLUGGED_TYPE_BUTT | Reserved.|
68
69
70## Function Description
71
72
73### OH_BatteryInfo_GetCapacity()
74
75```
76int32_t OH_BatteryInfo_GetCapacity ()
77```
78
79**Description**
80
81Obtains the current battery capacity.
82
83**System capability**: SystemCapability.PowerManager.BatteryManager.Core
84
85**Since**: 13
86
87**Returns**
88
89A number in the range from 0 to 100.
90
91
92### OH_BatteryInfo_GetPluggedType()
93
94```
95BatteryInfo_BatteryPluggedType OH_BatteryInfo_GetPluggedType ()
96```
97
98**Description**
99
100Obtains the plug type.
101
102**System capability**: SystemCapability.PowerManager.BatteryManager.Core
103
104**Since**: 13
105
106**Returns**
107
108PLUGGED_TYPE_NONE: No power supply.
109
110PLUGGED_TYPE_AC: AC charging.
111
112PLUGGED_TYPE_USB: USB DC charging.
113
114PLUGGED_TYPE_WIRELESS: wireless charging.
115
116PLUGGED_TYPE_BUTT: unknown plug type.
117
118
119## Variable Description
120
121
122### COMMON_EVENT_KEY_CAPACITY
123
124```
125const char* COMMON_EVENT_KEY_CAPACITY = "soc"
126```
127
128**Description**
129
130Defines the common event indicating a battery capacity change.
131
132**Since**: 13
133
134
135### COMMON_EVENT_KEY_CHARGE_STATE
136
137```
138const char* COMMON_EVENT_KEY_CHARGE_STATE = "chargeState"
139```
140
141**Description**
142
143Defines the common event indicating a charging status change.
144
145**Since**: 13
146
147
148### COMMON_EVENT_KEY_PLUGGED_TYPE
149
150```
151const char* COMMON_EVENT_KEY_PLUGGED_TYPE = "pluggedType"
152```
153
154**Description**
155
156Defines the common event indicating a plug type change.
157
158**Since**: 13
159