ohos.battery_info
Note:
Currently in the beta phase.
This module primarily provides query interfaces for battery status and charging/discharging states.
Importing the Module
import kit.BasicServicesKit.*
Usage Instructions
API sample code usage instructions:
- If the sample code's first line contains a "// index.cj" comment, it indicates the sample can be compiled and run in the "index.cj" file of the Cangjie template project.
- If the sample requires obtaining the Context application context, it needs to be configured in the "main_ability.cj" file of the Cangjie template project.
For details about the sample project and configuration template mentioned above, refer to Cangjie Sample Code Instructions.
class BatteryInfo
public class BatteryInfo {}
Function: Class describing battery information.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
static prop batteryCapacityLevel
public static prop batteryCapacityLevel: BatteryCapacityLevel
Function: Indicates the current device's battery charge level.
Type: BatteryCapacityLevel
Read/Write Permission: Read-only
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
static prop batterySOC
public static prop batterySOC: Int32
Function: Indicates the current device's remaining battery percentage.
Type: Int32
Read/Write Permission: Read-only
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
static prop batteryTemperature
public static prop batteryTemperature: Int32
Function: Indicates the current device's battery temperature.
Type: Int32
Read/Write Permission: Read-only
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
static prop chargingStatus
public static prop chargingStatus: BatteryChargeState
Function: Indicates the current device's battery charging status.
Type: BatteryChargeState
Read/Write Permission: Read-only
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
static prop healthStatus
public static prop healthStatus: BatteryHealthState
Function: Indicates the current device's battery health status.
Type: BatteryHealthState
Read/Write Permission: Read-only
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
static prop isBatteryPresent
public static prop isBatteryPresent: Bool
Function: Indicates whether the current device supports a battery or if the battery is present.
Type: Bool
Read/Write Permission: Read-only
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
static prop nowCurrent
public static prop nowCurrent: Int32
Function: Indicates the current device's battery current.
Type: Int32
Read/Write Permission: Read-only
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
static prop pluggedType
public static prop pluggedType: BatteryPluggedType
Function: Indicates the type of charger currently connected to the device.
Type: BatteryPluggedType
Read/Write Permission: Read-only
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
static prop technology
public static prop technology: String
Function: Indicates the current device's battery technology model.
Type: String
Read/Write Permission: Read-only
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
static prop voltage
public static prop voltage: Int32
Function: Indicates the current device's battery voltage.
Type: Int32
Read/Write Permission: Read-only
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
enum BatteryCapacityLevel
public enum BatteryCapacityLevel <: Equatable<BatteryCapacityLevel> & ToString {
| LevelFull
| LevelHigh
| LevelNormal
| LevelLow
| LevelWarning
| LevelCritical
| LevelShutdown
| ...
}
Function: Represents battery charge levels.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
Parent Types:
- Equatable<BatteryCapacityLevel>
- ToString
LevelCritical
LevelCritical
Function: Indicates the battery charge level is critically low.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
LevelFull
LevelFull
Function: Indicates the battery charge level is full.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
LevelHigh
LevelHigh
Function: Indicates the battery charge level is high.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
LevelLow
LevelLow
Function: Indicates the battery charge level is low.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
LevelNormal
LevelNormal
Function: Indicates the battery charge level is normal.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
LevelShutdown
LevelShutdown
Function: Indicates the battery charge level is at shutdown threshold.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
LevelWarning
LevelWarning
Function: Indicates the battery charge level is at warning threshold.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
func !=(BatteryCapacityLevel)
public operator func !=(other: BatteryCapacityLevel): Bool
Function: Performs inequality comparison on battery charge levels.
Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| other | BatteryCapacityLevel | Yes | - | Battery charge level. |
Return Value:
| Type | Description |
|---|---|
| Bool | Returns true if battery charge levels differ, otherwise false. |
func ==(BatteryCapacityLevel)
public operator func ==(other: BatteryCapacityLevel): Bool
Function: Performs equality comparison on battery charge levels.
Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| other | BatteryCapacityLevel | Yes | - | Battery charge level. |
Return Value:
| Type | Description |
|---|---|
| Bool | Returns true if battery charge levels are equal, otherwise false. |
func toString()
public func toString(): String
Function: Returns the string representation of the battery charge level.
Return Value:
| Type | Description |
|---|---|
| String | String corresponding to the battery charge level value. |
enum BatteryChargeState
public enum BatteryChargeState <: Equatable<BatteryChargeState> & ToString {
| UnknownChargeState
| Enabled
| Disabled
| Full
| ...
}
Function: Represents battery charging states.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
Parent Types:
- Equatable<BatteryChargeState>
- ToString
Disabled
Disabled
Function: Indicates the battery charging state is disabled.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
Enabled
Enabled
Function: Indicates the battery charging state is enabled.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
Full
Full
Function: Indicates the battery charging state is fully charged.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
UnknownChargeState
UnknownChargeState
Function: Indicates the battery charging state is unknown.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
func !=(BatteryChargeState)
public operator func !=(other: BatteryChargeState): Bool
Function: Performs inequality comparison on battery charging states.
Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| other | BatteryChargeState | Yes | - | Battery charging state. |
Return Value:
| Type | Description |
|---|---|
| Bool | Returns true if battery charging states differ, otherwise false. |
func ==(BatteryChargeState)
public operator func ==(other: BatteryChargeState): Bool
Function: Performs equality comparison on battery charging states.
Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| other | BatteryChargeState | Yes | - | Battery charging state. |
Return Value:
| Type | Description |
|---|---|
| Bool | Returns true if battery charging states are equal, otherwise false. |
func toString()
public func toString(): String
Function: Returns the string representation of the battery charging state.
Return Value:
| Type | Description |
|---|---|
| String | String corresponding to the battery charging state value. |
public enum BatteryHealthState <: Equatable<BatteryHealthState> & ToString {
| UnknownHealthState
| Good
| Overheat
| Overvoltage
| Cold
| Dead
| ...
}
Function: Represents battery health status.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
Parent Types:
- Equatable<BatteryHealthState>
- ToString
Cold
Cold
Function: Indicates the battery health status is cold.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
Dead
Dead
Function: Indicates the battery health status is dead.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
Good
Good
Function: Indicates the battery health status is normal.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
Overheat
Overheat
Function: Indicates the battery health status is overheating.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
Overvoltage
Overvoltage
Function: Indicates the battery health status is overvoltage.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
UnknownHealthState
UnknownHealthState
Function: Indicates the battery health status is unknown.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
func !=(BatteryHealthState)
public operator func !=(other: BatteryHealthState): Bool
Function: Compares battery health states for inequality.
Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| other | BatteryHealthState | Yes | - | Battery health state. |
Return Value:
| Type | Description |
|---|---|
| Bool | Returns true if battery health states differ, otherwise false. |
func ==(BatteryHealthState)
public operator func ==(other: BatteryHealthState): Bool
Function: Compares battery health states for equality.
Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| other | BatteryHealthState | Yes | - | Battery health state. |
Return Value:
| Type | Description |
|---|---|
| Bool | Returns true if battery health states are identical, otherwise false. |
func toString()
public func toString(): String
Function: Returns the string representation of battery health state.
Return Value:
| Type | Description |
|---|---|
| String | String corresponding to the battery health state value. |
enum BatteryPluggedType
public enum BatteryPluggedType <: Equatable<BatteryPluggedType> & ToString {
| UnknownType
| Ac
| Usb
| Wireless
| ...
}
Function: Represents the type of connected charger.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
Parent Types:
- Equatable<BatteryPluggedType>
- ToString
Ac
Ac
Function: Indicates the connected charger type is AC charger.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
UnknownType
UnknownType
Function: Indicates the connected charger type is not obtained.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
Usb
Usb
Function: Indicates the connected charger type is USB.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
Wireless
Wireless
Function: Indicates the connected charger type is wireless charger.
System Capability: SystemCapability.PowerManager.BatteryManager.Core
Since: 22
func !=(BatteryPluggedType)
public operator func !=(other: BatteryPluggedType): Bool
Function: Compares charger types for inequality.
Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| other | BatteryPluggedType | Yes | - | Charger type. |
Return Value:
| Type | Description |
|---|---|
| Bool | Returns true if charger types differ, otherwise false. |
func ==(BatteryPluggedType)
public operator func ==(other: BatteryPluggedType): Bool
Function: Compares charger types for equality.
Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| other | BatteryPluggedType | Yes | - | Charger type. |
Return Value:
| Type | Description |
|---|---|
| Bool | Returns true if charger types are identical, otherwise false. |
func toString()
public func toString(): String
Function: Returns the string representation of charger type information.
Return Value:
| Type | Description |
|---|---|
| String | String corresponding to the charger type value. |