public final class DLBatteryManager
extends java.lang.Object
DLBatteryManager allows to read specific battery parameters.
Lifetime and realtime values can be read through the BatteryStatus and manufacturer information can be read through the ManufacturerInfo. This class is also used to retrieve information and setup the current charging profile between the ones available, through the ChargingProfile.| Modifier and Type | Method and Description |
|---|---|
int |
addBatteryEventListener(BatteryEventListener listener)
Registers a
BatteryEventListener to be notified of the BatteryManager events. |
BatteryStatus |
getBatteryStatus()
Reads the battery status.
|
ChargingProfile |
getCurrentChargingProfile()
Gets the current charging profile setup in this device.
|
static DLBatteryManager |
getInstance()
Returns an instance of the
DLBatteryManager. |
int |
getIntProperty(BatteryInfo prop)
Reads the integer value of a specific battery property.
|
ManufacturerInfo |
getManufacturerInfo()
Reads the battery manufacturer info.
|
java.lang.String |
getStringProperty(BatteryInfo prop)
Reads the String value of a specific battery property.
|
java.util.List<ChargingProfile> |
getSupportedChargingProfiles()
Gets the supported charging profiles in this device.
|
void |
initBatteryEvents(android.content.Context context)
Prepare the DlBatteryManager to receive events from the Android PowerManger Service.
|
int |
removeBatteryEventListener(BatteryEventListener listener)
Unregisters a
BatteryEventListener associated with the BatteryManager. |
void |
setCurrentChargingProfile(ChargingProfile chargingProfile)
Sets the current charging profile.
|
public static DLBatteryManager getInstance()
DLBatteryManager.public void initBatteryEvents(android.content.Context context)
addBatteryEventListener(com.datalogic.device.battery.BatteryEventListener) fails with error BatteryException.CONTEXT_UNKNOWN.context - The context of the caller.public ManufacturerInfo getManufacturerInfo()
ManufacturerInfo
object containing all battery manufacturer info.public BatteryStatus getBatteryStatus()
BatteryStatus
object containing all battery status.public java.util.List<ChargingProfile> getSupportedChargingProfiles()
ChargingProfile
objects, each representing one of the supported charging profile.
The list can be empty in case no charging profile is supported in the
current device.public void setCurrentChargingProfile(ChargingProfile chargingProfile)
chargingProfile - The ChargingProfile
to set.public ChargingProfile getCurrentChargingProfile()
ChargingProfile
currently setup in this device.public int getIntProperty(BatteryInfo prop)
BatteryInfo. Call this method only with
BatteryInfo related to properties of type int. For
properties of type String, use getStringProperty() instead.prop - The required BatteryInfo.int
The value of the specified property, or throws an
Exception in case of failure.public java.lang.String getStringProperty(BatteryInfo prop)
BatteryInfo. Call this method only with
BatteryInfo related to properties of type String. For
properties of type int, call getIntProperty() instead.prop - The required BatteryInfo.String
The value of the specified property, or throws an
Exception in case of failure.public int addBatteryEventListener(BatteryEventListener listener)
BatteryEventListener to be notified of the BatteryManager events. BatteryException.CONTEXT_UNKNOWN
if initBatteryEvents(android.content.Context) has not been not previously called to register the client's context. removeBatteryEventListener(com.datalogic.device.battery.BatteryEventListener) before the application
closes to properly shut down the listener and avoid memory leaks.listener - The BatteryEventListener that will be called to signal a BatteryEventint BatteryException.SUCCESS in case of success,
otherwise a possible error code, matching one of the BatteryException error constants.BatteryException - in case of error, when exceptions are enabled through the ErrorManager singleton.public int removeBatteryEventListener(BatteryEventListener listener)
BatteryEventListener associated with the BatteryManager.listener - The BatteryEventListener that will be no more notified.int BatteryException.SUCCESS in case of success,
otherwise a possible error code, matching one of the BatteryException error constants.BatteryException - in case of error, when exceptions are enabled through the ErrorManager singleton.