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


监控系统, 铃声, 来电, 代码, 播放
#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               
        }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值