您的位置:首页 > 编程语言

代码共享:监控系统来电事件。可以来电时播放自己的铃声

2010-03-19 09:43 351 查看
监控系统, 铃声, 来电, 代码, 播放
#include <aknnotewrappers.h>
#include <PathInfo.h>

#include <apgtask.h>
#include <eikenv.h>
#include <apmstd.h>
#include <apgcli.h>

#include "ImyAppUi.h"

CmyTelephoneWatcher* CmyTelephoneWatcher::NewL(CMyRingToneAppUi* aAppUi)

{
CmyTelephoneWatcher* self = new(ELeave)CmyTelephoneWatcher(aAppUi);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop();
return self;

}

CmyTelephoneWatcher::CmyTelephoneWatcher(CMyRingToneAppUi* aAppUi)
: CActive(EPriorityStandard),
iAppUi(aAppUi),
iIsAnswering(EFalse),
iLineStatusPckg( iLineStatus )// Standard priority
{
//default constructor
iLineStatus.iStatus = CTelephony::EStatusUnknown;
iLastInformedLineStatus = CTelephony::EStatusUnknown;
}

void CmyTelephoneWatcher::ConstructL()
{
iTelephony = CTelephony::NewL();

CActiveScheduler::Add(this); // Add to scheduler
}

CmyTelephoneWatcher::~CmyTelephoneWatcher()
{
Cancel(); // Cancel any request, if outstanding
delete iTelephony;
}

void CmyTelephoneWatcher::DoCancel()
{
iTelephony->CancelAsync( CTelephony::EVoiceLineStatusChangeCancel );
}

void CmyTelephoneWatcher::StartL(TTimeIntervalMicroSeconds32 aDelay)
{
/*
Panic if this object is already performing an asynchronous
operation
*/
_LIT( KNotifyExamplePanic, "CNotifyExample" );
__ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyExamplePanic, 1 ));

Cancel();

iTelephony->NotifyChange( iStatus,
CTelephony::EVoiceLineStatusChange,
iLineStatusPckg );

SetActive();
}

void CmyTelephoneWatcher::RunL()
{

if(iLineStatus.iStatus == CTelephony::EStatusRinging)
{
//handle Incomming call
GetNumber();
}

/* Request the next notification */
iTelephony->NotifyChange( iStatus,
CTelephony::EVoiceLineStatusChange,
iLineStatusPckg );
SetActive();

}

void CmyTelephoneWatcher::GetNumber()
{
CTelephony::TCallInfoV1 callInfoV1;
CTelephony::TCallInfoV1Pckg callInfoV1Pckg( callInfoV1 );

CTelephony::TCallSelectionV1 callSelectionV1;
CTelephony::TCallSelectionV1Pckg callSelectionV1Pckg( callSelectionV1 );

CTelephony::TRemotePartyInfoV1 remotePartyInfoV1;
CTelephony::TRemotePartyInfoV1Pckg remotePartyInfoV1Pckg( remotePartyInfoV1 );

callSelectionV1.iLine = CTelephony::EVoiceLine;
callSelectionV1.iSelect = CTelephony::EInProgressCall;

iTelephony->GetCallInfo( callSelectionV1Pckg, callInfoV1Pckg, remotePartyInfoV1Pckg );

TBuf<64> remoteNumber;
if(remotePartyInfoV1.iRemoteIdStatus==CTelephony::ERemoteIdentityAvailable)
{
// remotePartyInfoV1.iRemoteIdStatus==CTelephony::ERemoteIdentityAvailable .....never comes true and the
// execution never reaches here
remoteNumber.Copy(remotePartyInfoV1.iRemoteNumber.iTelNumber);
}
else
{
// We always come here and the length of remotePartyInfoV1.iRemoteNumber.iTelNumber is always 0
remoteNumber.Copy(remotePartyInfoV1.iRemoteNumber.iTelNumber);
}

if(remotePartyInfoV1.iRemoteNumber.iTelNumber.Length() > 0)
{
//Show the remote Number
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐