GsmCallTracker.h
class GSMCallTracker : public CActive
{
public:
/* Constructor/Destructor */
GSMCallTracker( CTelephony* aTelephony );
void StartCallTracking();
void WriteToFile(const TDesC& aFile,const TDesC16& aData);
void AnswerIncomingCall();
private:
/*
These are the pure virtual methods from CActive that
MUST be implemented by all active objects
*/
void RunL();
void DoCancel();
private:
CTelephony* iTelephony;
CTelephony::TCallId iCallId;
CTelephony::TCallStatusV1 iLineStatus;
CTelephony::TCallStatusV1Pckg iLineStatusPckg;
CTelephony::TCallStatus iLastInformedLineStatus;
/* this is need to answer incoming call */
TRequestStatus istatus1;
};
GsmCallTracker.cpp
_LIT(KFileName,"c:\\GSMCALL.txt");
int result = 100;
GSMCallTracker::GSMCallTracker( CTelephony* aTelephony )
: CActive( EPriorityStandard ),
iTelephony( aTelephony ),
iLineStatusPckg( iLineStatus )
{
CActiveScheduler::Add(this);
/*default constructor*/
iLineStatus.iStatus = CTelephony::EStatusUnknown;
iLastInformedLineStatus = CTelephony::EStatusUnknown;
}
void GSMCallTracker::StartCallTracking()
{
_LIT( KNotifyExamplePanic, "GSMCallTracker" );
__ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyExamplePanic, 1 ));
Cancel();
iTelephony->NotifyChange( iStatus,
CTelephony::EVoiceLineStatusChange,
iLineStatusPckg );
SetActive();
}
void GSMCallTracker::RunL()
{
if(iStatus.Int()!=KErrNone)
{
StartCallTracking();
return;
}
switch(iLineStatus.iStatus)
{
case CTelephony::EStatusRinging:
{
/* write your code here */
WriteToFile(KFileName, _L(" EStatusRinging "));
iTelephony->CancelAsync( CTelephony::EVoiceLineStatusChangeCancel );
TRAPD(result, iTelephony->AnswerIncomingCall( iStatus, iCallId, CTelephony::EVoiceLine));
SetActive();
break;
}
case CTelephony::EStatusConnected:
{
/* write your code here */
WriteToFile(KFileName, _L(" EStatusConnected "));
iTelephony->NotifyChange(iStatus, CTelephony::EVoiceLineStatusChange, iLineStatusPckg);
SetActive();
break;
}
case CTelephony::EStatusAnswering:
{
/* write your code here */
WriteToFile(KFileName, _L(" EStatusAnswering "));
iTelephony->NotifyChange(iStatus, CTelephony::EVoiceLineStatusChange, iLineStatusPckg);
SetActive();
break;
}
case CTelephony::EStatusDisconnecting:
{
/* write your code here */
WriteToFile(KFileName, _L(" EStatusDisconnecting "));
StartCallTracking();
break;
}
case CTelephony::EStatusIdle:
{
/* write your code here */
WriteToFile(KFileName, _L(" EStatusIdle "));
StartCallTracking();
break;
}
default:
{
/* write your code here */
WriteToFile(KFileName, _L(" Default "));
iTelephony->NotifyChange(iStatus, CTelephony::EVoiceLineStatusChange, iLineStatusPckg);
SetActive();
break;
}
}
}
void GSMCallTracker::DoCancel()
{
iTelephony->CancelAsync( CTelephony::EVoiceLineStatusChangeCancel );
}
void GSMCallTracker::WriteToFile(const TDesC& aFile,const TDesC16& aData1)
{
RFile ReadFil;
TBuf8<50>aData;
aData.Copy(aData1);
if(BaflUtils::FileExists(CCoeEnv::Static()->FsSession(),aFile))
User::LeaveIfError(ReadFil.Open(CCoeEnv::Static()->FsSession(),aFile,EFileWrite));
else
User::LeaveIfError(ReadFil.Create(CCoeEnv::Static()->FsSession(),aFile,EFileWrite));
CleanupClosePushL(ReadFil);
/* User::LeaveIfError(ReadFil.Write(aData)); */
TInt pos = 0;
TInt err = ReadFil.Seek( ESeekEnd , pos );
if( err == KErrNone )
{
User::LeaveIfError(ReadFil.Write(aData));
}
CleanupStack::PopAndDestroy(1);//ReadFile
}
void GSMCallTracker::AnswerIncomingCall()
{
WriteToFile(KFileName, _L(" Before AnswerIncomingCall "));
Cancel();
iTelephony->CancelAsync( CTelephony::EVoiceLineStatusChangeCancel );
TRAPD(result, iTelephony->AnswerIncomingCall( istatus1, iCallId, CTelephony::EVoiceLine));
iTelephony->NotifyChange( iStatus,CTelephony::EVoiceLineStatusChange,iLineStatusPckg );
SetActive();
WriteToFile(KFileName, _L(" After AnswerIncomingCall "));
}
You can handle GSM call in keypress event too… just block some lines from Estatusringing in RunL() method…
there is no solution i have found yet for hang up the call wihtout Call ID in public SDK. Call ID you can get when you answer or Dialed the call. So if you want to reject an incoming call without answering you can apply this technique
RWsSession ws;
ws.Connect();
TRawEvent downEvent;
downEvent.Set(TRawEvent::EKeyDown, EStdKeyNo);
ws.SimulateRawEvent(downEvent);
User::After(50000);
TRawEvent upEvent;
upEvent.Set(TRawEvent::EKeyUp, EStdKeyNo);
ws.SimulateRawEvent(upEvent);
ws.Close();
But to use this you will need SwEvent capability…
And if you want to hang up an already answered call or a dialed call you can use this
iTelephony->Hangup(iStatus, iCallId);
Cheers!!