Symbian
Symbian OS Library

FAQ-0993 How can I detect battery strength on a phone ?

[Index][spacer] [Previous] [Next]



 

Classification: C++ Category: Base
Created: 03/02/2004 Modified: 04/02/2004
Number: FAQ-0993
Platform: Symbian OS v6.0, Symbian OS v6.1, Symbian OS v7.0, Symbian OS v7.0s

Question:
How can I write some code to detect what strength is available from the battery of a phone ?

Answer:

You can detect the battery strength using the System Agent API or HAL. Bear in mind however that on real devices the manufacturer may have a different API that is used and these APIs will not be functional but will return a default value.

1) RSystemAgent systemAgent;
User::LeaveIfError(systemAgent.Connect());
TInt strength = systemAgent.GetState(KUidBatteryStrength);

using the enum
enum TSABatteryStrength
{
ESABatteryAlmostEmpty,
ESABatteryLow,
ESABatteryFull
};

(see sacls.h)

2) TInt batStatus=HAL::EPowerBatteryStatus_Zero;
TInt err=HAL::Get(HAL::EPowerBatteryStatus, batStatus);
using the enum
enum TPowerBatteryStatus
{
EPowerBatteryStatus_Replace
EPowerBatteryStatus_Low
EPowerBatteryStatus_Good
};
(see hal_data.h)

3) RMobilePhone::GetBatteryInfo() - provides the battery power as a percentage.
This API is available from Symbian OS v7.0; It is available only to Symbian OS Devevelopment Kit (DevKit) licensees.
This is documented in the Developer library under:
» Developer Library » Symbian OS Guide » C++ API guide » Telephony » Using Multimode ETel » Multimode phone » How to get the phone power status.

* Note that the client-side API will always exist, however the implementation depends on the licensee. Therefore this functionality may not be present on a particular phone.