public final class

DLBatteryManager

extends Object
java.lang.Object
   ↳ com.datalogic.device.battery.DLBatteryManager

Class Overview

The 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.

Summary

Public Methods
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.
String getStringProperty(BatteryInfo prop)
Reads the String value of a specific battery property.
List<ChargingProfile> getSupportedChargingProfiles()
Gets the supported charging profiles in this device.
void initBatteryEvents(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.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public int addBatteryEventListener (BatteryEventListener listener)

Added in revision 21

Registers a BatteryEventListener to be notified of the BatteryManager events.
A call to addBatteryEventListener will fail with error CONTEXT_UNKNOWN if initBatteryEvents(Context) has not been not previously called to register the client's context.
Call removeBatteryEventListener(BatteryEventListener) before the application closes to properly shut down the listener and avoid memory leaks.

Parameters
listener The BatteryEventListener that will be called to signal a BatteryEvent
Returns
  • int SUCCESS in case of success, otherwise a possible error code, matching one of the BatteryException error constants.
Throws
BatteryException in case of error, when exceptions are enabled through the ErrorManager singleton.

public BatteryStatus getBatteryStatus ()

Added in revision 13

Reads the battery status.

Returns

public ChargingProfile getCurrentChargingProfile ()

Added in revision 13

Gets the current charging profile setup in this device.

Returns

public static DLBatteryManager getInstance ()

Added in revision 13

Returns an instance of the DLBatteryManager.

Returns
  • The Battery Manager.

public int getIntProperty (BatteryInfo prop)

Added in revision 13

Reads the integer value of a specific battery property. This value is present as one of the properties of the BatteryInfo. Call this method only with BatteryInfo related to properties of type int. For properties of type String, use getStringProperty() instead.

Parameters
prop The required BatteryInfo.
Returns
  • int The value of the specified property, or throws an Exception in case of failure.

public ManufacturerInfo getManufacturerInfo ()

Added in revision 13

Reads the battery manufacturer info.

Returns

public String getStringProperty (BatteryInfo prop)

Added in revision 13

Reads the String value of a specific battery property. This value is present as one of the properties of the BatteryInfo. Call this method only with BatteryInfo related to properties of type String. For properties of type int, call getIntProperty() instead.

Parameters
prop The required BatteryInfo.
Returns
  • String The value of the specified property, or throws an Exception in case of failure.

public List<ChargingProfile> getSupportedChargingProfiles ()

Added in revision 13

Gets the supported charging profiles in this device. You can use one of the returning objects to setup the desired charging profile.

Returns
  • A list of 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 initBatteryEvents (Context context)

Added in revision 21

Prepare the DlBatteryManager to receive events from the Android PowerManger Service.
If not called the addBatteryEventListener(BatteryEventListener) fails with error CONTEXT_UNKNOWN. This method cannot be called from a BroadcastReceiver component; that is, from a BroadcastReceiver that is declared in an application's manifest. It is okay, however, to call this method from another BroadcastReceiver that has itself been registered at run time with registerReceiver(BroadcastReceiver, IntentFilter), since the lifetime of such a registered BroadcastReceiver is tied to the object that registered it. See for more details: registerReceiver(BroadcastReceiver receiver, IntentFilter filter) and ReceiverCallNotAllowedException

Parameters
context The context of the caller.
Throws
BatteryException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int removeBatteryEventListener (BatteryEventListener listener)

Added in revision 21

Unregisters a BatteryEventListener associated with the BatteryManager.

Parameters
listener The BatteryEventListener that will be no more notified.
Returns
  • int SUCCESS in case of success, otherwise a possible error code, matching one of the BatteryException error constants.
Throws
BatteryException in case of error, when exceptions are enabled through the ErrorManager singleton.

public void setCurrentChargingProfile (ChargingProfile chargingProfile)

Added in revision 13

Sets the current charging profile. This setting is persistent to device reboots or even factory resets.

Parameters
chargingProfile The ChargingProfile to set.