symbian 來電攔截

來源:互聯網
上載者:User

功能描述:

1.擷取來電和去電的號碼(此處用到S60 3rd的API);
2.對來電進行掛斷(使用類比按鍵和API掛斷的方式);
3.修改手機的情景模式(改為靜音);
4.開啟/關閉音量和震動;
5.修改通話過程中耳機和話筒的音量;
6.開啟/關閉免提;
7.開啟/關閉手機背景光。

代碼參考:(如有更好的,望指點)

#ifndef CTELDIAL_H_<br />#define CTELDIAL_H_</p><p>//etel core api<br />#include<br />#include </p><p>#include </p><p>//for the vibra and ring<br />#include<br />#include<br />#include<br />#include </p><p>#include //CR Keys To Control Phone Volume<br />#include //CRepository</p><p>//for the light<br />#include </p><p>//for the loud speaker<br />#include<br />#include </p><p>//simulation key<br />#include </p><p>class CTelDial: public CActive<br />{</p><p>public:<br />static CTelDial* NewL();<br />void GetDefaultTSY(TDes& aTSYName);<br />void StartObserve();</p><p>//the dial<br />void GetDialNumber();<br />void SetDialNumber(const TDes& aSetDialNumber);<br />bool CmpDialedNumber();<br />void OpenLoudSpeaker();<br />void SetCallVolumn(const TInt aspeakvol);<br />//the receive</p><p>void GetReceivedNumber();<br />void SetReceiveNumber(const TDes& aSetReceiveNumber);<br />bool CmpReceivedNumber();<br />//detect<br />void SetDetectNumber(const TDes& aSetDetectNumber);<br />bool CmpDetectNumber();<br />//light and vibra<br />void SetVibraAndRing();<br />void RecoverVibraAndRing();<br />//simulate key<br />void SimulateRedKey();<br />void SimulateRightKey();<br />//release<br />void ReleaseOneCall();<br />~CTelDial();</p><p>protected:<br />void RunL();<br />void DoCancel();</p><p>private:<br />CTelDial();<br />void ConstructL();<br />static CTelDial* NewLC();</p><p>private:<br />//const TUid KUidSound =0x101f8798;<br />//Etel Api<br />private:</p><p>TBuf <20>iTSYName;<br />RTelServer iServer;<br />RPhone iPhone;<br />RPhone::TLineInfo iphonelineinfo;<br />RLine iLine;<br />RLine::TLineInfo ilineinfo;<br />RCall::TStatus iCallStatus;<br />//from the etelmm<br />RMobileCall iMCall;</p><p>//the numbers<br />private:<br />TBuf <11> iNumberDial;<br />TBuf <11> iNumberReceive;<br />TBuf <11> iNumberDialSet;<br />TBuf <11> iNumberReceiveSet;<br />TBuf <11> iNumberDetectSet;</p><p>//to change the repository<br />private:<br />CRepository* irepository;</p><p>//for the vibra and ring<br />private:<br />TBool ivibratype;<br />TProfileRingingType iRingingType;</p><p>private:<br />CHWRMLight* ilight;</p><p>private:<br />RWindowGroup iwindowgroup;</p><p>//simulate key<br />private:<br />RWsSession ws;<br />TRawEvent ev1;</p><p>};</p><p>#endif</p><p>#include<br />#include<br />#include "CTel_3rd.h"</p><p>//constructed function<br />void CTelDial::ConstructL()<br />{<br />//add the cteldial to the active scheduler<br />CActiveScheduler::Add(this);</p><p>ilight = CHWRMLight::NewL();</p><p>itelephony = CTelephony::NewL();</p><p>// iwindowgroup.CaptureKey(EStdKey)<br />}</p><p>//RunL ,if the number received is equel to the setted number<br />void CTelDial::RunL()<br />{<br />if (KErrNone == iStatus.Int())<br />{<br />switch (iLineStatus.iStatus)<br />{<br />case CTelephony::EStatusDisconnecting:<br />{<br />ilight->LightOffL(CHWRMLight::EPrimaryDisplayAndKeyboard);<br />RProperty::Set(KTelephonyAudioOutput,KTelephonyAudioOutputPreference,EPSPrivate);<br />if (irepository)<br />{<br />delete irepository;<br />irepository = NULL;<br />}<br />break;<br />}<br />case CTelephony::EStatusDialling:<br />{<br />GetDialNumber();<br />if (CmpDialedNumber())<br />{<br />SimulateRedKey();<br />}<br />break;<br />}<br />case CTelephony::EStatusRinging:<br />{<br />//turn off the vibra and ring the moment the phone is open<br />GetReceivedNumber();<br />if (CmpReceivedNumber())<br />{<br />SimulateRedKey();<br />ilight->LightOffL(CHWRMLight::EPrimaryDisplayAndKeyboard);<br />}<br />//compare the detect number, if it is, answer it.<br />else if (CmpDetectNumber())<br />{<br />// SetVibraAndRing();<br />//this is to turn off the ring<br />SimulateRightKey();<br />itelephony->AnswerIncomingCall(iStatus, iCallid);<br />//ilight->LightOffL(CHWRMLight::EPrimaryDisplayAndKeyboard);<br />OpenLoudSpeaker();<br />SetCallVolumn(0);<br />}<br />else<br />{<br />//if it's the normal call, recover the vibra and ring<br />//turn off it when the call is over<br />RecoverVibraAndRing();<br />}<br />break;<br />}<br />default:<br />{<br />ilight->LightOffL(CHWRMLight::EPrimaryDisplayAndKeyboard);<br />break;<br />}<br />}<br />}<br />Cancel();<br />//if the status of line changes, it means some one is calling this phone<br />itelephony->NotifyChange(iStatus,<br />CTelephony::EVoiceLineStatusChange,<br />iLineStatusPckg);<br />}</p><p>//----------------------------------------------------<br />//CTelDial::StartObserve()<br />//observe the call<br />//----------------------------------------------------<br />void CTelDial::StartObserve()<br />{<br />Cancel();<br />//if the status of line changes, it means some one is calling this phone<br />itelephony->NotifyChange(iStatus,<br />CTelephony::EVoiceLineStatusChange,<br />iLineStatusPckg);<br />SetActive();//invoke the asynchronous function<br />}</p><p>//----------------------------------------------------<br />//CTelDial::SetVibraAndRing()<br />//turn off the vibra and ring<br />//----------------------------------------------------<br />void CTelDial::SetVibraAndRing()<br />{<br />MProEngEngine* iEngine = ProEngFactory::NewEngineL();<br />MProEngProfile* iProfile = iEngine->ActiveProfileLC();<br />MProEngToneSettings& iToneSetting = iProfile->ToneSettings();</p><p>//if vibra is on, turn off it<br />ivibratype = iToneSetting.VibratingAlert();<br />if (ivibratype)<br />{<br />iToneSetting.SetVibratingAlert(EFalse);<br />}</p><p>//turn off the ring<br />iRingingType = iToneSetting.RingingType();<br />if (EProfileRingingTypeSilent != iRingingType)<br />{<br />iToneSetting.SetRingingType(EProfileRingingTypeSilent);<br />}</p><p>iProfile->CommitChangeL();</p><p>iProfile->Release();<br />iEngine->Release();<br />}</p><p>//----------------------------------------------------<br />//CTelDial::RecoverVibraAndRing()<br />//recover the vibra and ring<br />//----------------------------------------------------<br />void CTelDial::RecoverVibraAndRing()<br />{<br />MProEngEngine* iEngine = ProEngFactory::NewEngineL();<br />MProEngProfile* iProfile = iEngine->ActiveProfileLC();<br />MProEngToneSettings& iToneSetting = iProfile->ToneSettings();</p><p>//recover<br />iToneSetting.SetVibratingAlert(ivibratype);<br />iToneSetting.SetRingingType(iRingingType);</p><p>iProfile->CommitChangeL();</p><p>iProfile->Release();<br />iEngine->Release();<br />}</p><p>//----------------------------------------------------<br />//CTelDial::GetReceivedNumber()<br />//get the incoming call number<br />//----------------------------------------------------<br />void CTelDial::GetReceivedNumber()<br />{<br />//in the 3rd<br />CTelephony::TCallInfoV1 iPhonyCallInfoV1;<br />CTelephony::TCallInfoV1Pckg iPhonyCallInfoV1Pckg(iPhonyCallInfoV1);</p><p>CTelephony::TCallSelectionV1 iPhonyCallSelectionV1;<br />CTelephony::TCallSelectionV1Pckg iPhonyCallSelectionV1Pckg(iPhonyCallSelectionV1);</p><p>CTelephony::TRemotePartyInfoV1 iPhonyRemotePartyInfoV1;<br />CTelephony::TRemotePartyInfoV1Pckg iPhonyRemotePartyInfoV1Pckg( iPhonyRemotePartyInfoV1 );</p><p>CTelephony::TCallStatusV1 iPhonyCallStatusV1;<br />CTelephony::TCallStatusV1Pckg iPhonyCallStatusV1Pckg(iPhonyCallStatusV1);</p><p>iPhonyCallSelectionV1.iLine = CTelephony::EVoiceLine;<br />iPhonyCallSelectionV1.iSelect = CTelephony::EInProgressCall;</p><p>itelephony->GetLineStatus(CTelephony::EVoiceLine, iPhonyCallStatusV1Pckg);<br />itelephony->GetCallInfo(iPhonyCallSelectionV1Pckg, iPhonyCallInfoV1Pckg, iPhonyRemotePartyInfoV1Pckg);</p><p>if (CTelephony::ERemoteIdentityAvailable == iPhonyRemotePartyInfoV1.iRemoteIdStatus)<br />{<br />if (iPhonyRemotePartyInfoV1.iRemoteNumber.iTelNumber.Length() > 0)<br />{<br />//Incoming call number<br />iNumberReceive = iPhonyRemotePartyInfoV1.iRemoteNumber.iTelNumber;<br />}<br />}<br />}</p><p>//----------------------------------------------------<br />//CTelDial::GetDialNumber()<br />//get the outgoing call number<br />//----------------------------------------------------<br />void CTelDial::GetDialNumber()<br />{<br />CTelephony::TCallInfoV1 iPhonyCallInfoV1;<br />CTelephony::TCallInfoV1Pckg iPhonyCallInfoV1Pckg(iPhonyCallInfoV1);</p><p>CTelephony::TCallSelectionV1 iPhonyCallSelectionV1;<br />CTelephony::TCallSelectionV1Pckg iPhonyCallSelectionV1Pckg(iPhonyCallSelectionV1);</p><p>CTelephony::TRemotePartyInfoV1 iPhonyRemotePartyInfoV1;<br />CTelephony::TRemotePartyInfoV1Pckg iPhonyRemotePartyInfoV1Pckg( iPhonyRemotePartyInfoV1 );</p><p>iPhonyCallSelectionV1.iLine = CTelephony::EVoiceLine;<br />iPhonyCallSelectionV1.iSelect = CTelephony::EInProgressCall;</p><p>itelephony->GetCallInfo(iPhonyCallSelectionV1Pckg, iPhonyCallInfoV1Pckg, iPhonyRemotePartyInfoV1Pckg);</p><p>if (iPhonyCallInfoV1.iDialledParty.iTelNumber.Length() > 0)<br />{<br />//Outgoing call number<br />iNumberDial = iPhonyCallInfoV1.iDialledParty.iTelNumber;<br />}<br />}</p><p>bool CTelDial::CmpDialedNumber()<br />{<br />if (iNumberDialSet == iNumberDial)<br />{<br />return true;<br />}<br />else<br />{<br />return false;<br />}<br />}</p><p>bool CTelDial::CmpReceivedNumber()<br />{<br />if (iNumberReceiveSet == iNumberReceive)<br />{<br />return true;<br />}<br />else<br />{<br />return false;<br />}<br />}</p><p>bool CTelDial::CmpDetectNumber()<br />{<br />if (iNumberDetectSet == iNumberReceive)<br />{<br />return true;<br />}<br />else<br />{<br />return false;<br />}<br />}</p><p>void CTelDial::SetDialNumber(const TDes& aSetDialNumber)<br />{<br />iNumberDialSet.Copy(aSetDialNumber);<br />}</p><p>void CTelDial::SetReceiveNumber(const TDes& aSetReceiveNumber)<br />{<br />iNumberReceiveSet.Copy(aSetReceiveNumber);<br />}</p><p>void CTelDial::SetDetectNumber(const TDes& aSetDetectNumber)<br />{<br />iNumberDetectSet.Copy(aSetDetectNumber);<br />}</p><p>//----------------------------------------------------<br />//CTelDial::OpenLoudSpeaker()<br />//open the loudspeaker<br />//----------------------------------------------------<br />void CTelDial::OpenLoudSpeaker()<br />{<br />TInt value;<br />TInt theerr = RProperty::Get(KTelephonyAudioOutput, KTelephonyAudioOutputPreference, value);<br />switch(value)<br />{<br />case EPSPrivate:<br />{<br />theerr = RProperty::Set(KTelephonyAudioOutput,KTelephonyAudioOutputPreference,EPSPublic);<br />break;<br />}<br />default:<br />break;<br />};<br />}</p><p>void CTelDial::SetCallVolumn(const TInt aspeakvol)<br />{<br />//To create a CRepository object for accessing Phone Volume repository:<br />//and it must be created while the phone is processing<br />irepository = CRepository::NewL(KCRUidCallHandling);</p><p>//turn the speaker's volumn to max<br />TBuf<10> lBufErr;<br />TInt lErr = irepository->Set(KTelephonyIncallLoudspeakerVolume, aspeakvol);<br />lBufErr.AppendNum(lErr);<br />if (KErrNone != lErr)<br />{<br />return;<br />}<br />}</p><p>void CTelDial::SimulateRedKey()<br />{<br />ws.Connect();<br />ev1.Set(TRawEvent::EKeyDown, EStdKeyNo);<br />ws.SimulateRawEvent(ev1);<br />User::After(100000);<br />ev1.Set(TRawEvent::EKeyUp, EStdKeyNo);<br />ws.SimulateRawEvent(ev1);<br />ws.Flush();<br />}</p><p>void CTelDial::SimulateRightKey()<br />{<br />ws.Connect();<br />ev2.Set(TRawEvent::EKeyDown, EKeyDevice1);<br />ws.SimulateRawEvent(ev2);<br />User::After(100000);<br />ev2.Set(TRawEvent::EKeyUp, EKeyDevice1);<br />ws.SimulateRawEvent(ev2);<br />ws.Flush();<br />}</p><p>CTelDial::CTelDial() :<br />CActive(CActive::EPriorityStandard),iLineStatusPckg(iLineStatus)<br />{<br />iLineStatus.iStatus = CTelephony::EStatusUnknown;<br />}</p><p>void CTelDial::DoCancel()<br />{<br />itelephony->CancelAsync(CTelephony::EVoiceLineStatusChangeCancel);<br />}</p><p>CTelDial::~CTelDial()<br />{<br />delete ilight;<br />}</p><p>//the three new functions<br />CTelDial* CTelDial::NewLC()<br />{<br />CTelDial* self = new (ELeave) CTelDial;<br />CleanupStack::PushL(self);<br />self->ConstructL();<br />return self;<br />}</p><p>CTelDial* CTelDial::NewL()<br />{<br />CTelDial* self = CTelDial::NewLC();<br />CleanupStack::Pop(self);<br />return self;<br />}</p><p>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.