如何判断手机连接上充电器了
文章信息
可以通过CTelephony类中的GetIndicator()来获得相关信息。
- 异步调用,我们可以通过调用CTelephony::EGetIndicatorCancel来取消它
所需链接库:
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);
}

