×
Namespaces

Variants
Actions
Revision as of 21:48, 25 December 2009 by vdharankar (Talk | contribs)

How to detect when a charger is connected

From Nokia Developer Wiki
Jump to: navigation, search
{{{width}}}

This is done using GetIndicator() function from CTelephony class.

  • Asynchronous call; so to cancel it use CTelephony::EGetIndicatorCancel


Libraries needed:

LIBRARY Etel3rdParty.lib and euser.lib


class CClientApp : public CActive
{
 
private:
CTelephony* iTelephony;
CTelephony::TIndicatorV1 iIndicatorV1;
CTelephony::TIndicatorV1Pckg iIndicatorV1Pckg;
public:
CClientApp(CTelephony* aTelephony);
void DetectCharger();
 
private:
void RunL();
void DoCancel();
};
 
CClientApp::CClientApp(CTelephony* aTelephony)
: CActive(EPriorityStandard),
iTelephony(aTelephony),
iIndicatorV1Pckg(iIndicatorV1)
{
//Constructor
CActiveScheduler::Add(this);
}
 
void CClientApp::DetectCharger()
{
iTelephony->GetIndicator(iStatus, iIndicatorV1Pckg);
SetActive();
}
 
void CClientApp::RunL()
{
if(iStatus==KErrNone)
{
if(iIndicatorV1.iCapabilities & CTelephony::KIndChargerConnected)
{
//We can detect when a charger is connected
if(iIndicatorV1.iIndicator & CTelephony::KIndChargerConnected)
{
//Now, charger is connected
}
else
{
//Here, charger is not connected
}
}
else
{
//Here, we do not know whether or not a charger is connected
}
}
}
 
//To cancel this asynchronous call
void CClientApp::DoCancel()
{
iTelephony->CancelAsync(CTelephony::EGetIndicatorCancel);
}




Wiki Internal Links

61 page views in the last 30 days.