Get Caller Number
Article Metadata
Below is the code illustarating how to get the remote party's telephone number. It is different for S60 3rd Edition and previous versions.
Pre S60 3rd Edition
Hearders Required:
#include <etel.h>
#include <etelmm.h>
Library required:
LIBRARY etel.libSource Code:
void GetRemotePartyPhoneNumberL(TDes& aPhoneNumber)
{
RTelServer etel;
// Connect to ETel server
User::LeaveIfError(etel.Connect());
CleanupClosePushL(etel);
// Load phone module. This is just to be on the safe side
// because it should have been loaded already
_LIT(KTsyName, "phonetsy.tsy");
User::LeaveIfError(etel.LoadPhoneModule(KTsyName));
RTelServer::TPhoneInfo phoneInfo;
// Get phone info. We need phone's name to open a phone
const TInt KPhoneIndex = 0;
User::LeaveIfError(etel.GetPhoneInfo(KPhoneIndex, phoneInfo));
RPhone phone;
// Open the phone
User::LeaveIfError(phone.Open(etel, phoneInfo.iName));
CleanupClosePushL(phone);
RPhone::TLineInfo lineInfo;
// Get line info. We need line's name to open it
const TInt KLineIndex = 0;
User::LeaveIfError(phone.GetLineInfo(KLineIndex, lineInfo));
RLine line;
// Open the line
User::LeaveIfError(line.Open(phone, lineInfo.iName));
CleanupClosePushL(line);
RLine::TCallInfo callInfo;
// Get call info. We need call's name to open it and get the info we need
const TInt KCallIndex = 0;
User::LeaveIfError(line.GetCallInfo(KCallIndex, callInfo));
RMobileCall call;
// Open the call
User::LeaveIfError(call.OpenExistingCall(line, callInfo.iCallName));
CleanupClosePushL(call);
RMobileCall::TMobileCallInfoV1 mobCallInfo;
RMobileCall::TMobileCallInfoV1Pckg mobCallInfoPckg(mobCallInfo);
// Get the call's info
User::LeaveIfError(call.GetMobileCallInfo(mobCallInfoPckg));
// We successfully got the call's info.
// Now copy the remote party's phone number to the target descriptor
aPhoneNumber.Copy(mobCallInfoPckg().iRemoteParty.iRemoteNumber.iTelNumber);
// Close all handles
CleanupStack::PopAndDestroy(4); // call, line, phone, etel
}
For S60 3rd edition
S60 3rd Edition
Hearders Required:
#include <Etel3rdParty.h>Library required:
LIBRARY Etel3rdParty.libSource:
void GetRemotePartyPhoneNumberL(TDes& aPhoneNumber)
{
// Create a CTelephony object
CTelephony* telephony = CTelephony::NewLC();
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;
// Get the call info
User::LeaveIfError(telephony->GetCallInfo(callSelectionV1Pckg,
callInfoV1Pckg, remotePartyInfoV1Pckg));
// Copy the remote party's phone number to the target descriptor
aPhoneNumber.Copy(remotePartyInfoV1Pckg().iRemoteNumber.iTelNumber);
CleanupStack::PopAndDestroy(); // telephony
}


This code not work for series 60 2nd FP3 (always return blank number) ... I hink problem here : // Get call info. We need call's name to open it and get the info we need const TInt KCallIndex = 0; User::LeaveIfError(line.GetCallInfo(KCallIndex, callInfo)); may be must use call index not equal to 0?
P.S. i think on series 60 2nd FP3 we can use CTelephony...
28 Sep
2009
Many applications need to get phone number remote party (caller of the call) for one or more reason, for example to implement custom call register in application which provides some more feature than pre-installed call register (logs).
This article is basic article which teaches the reader how to get caller number from incoming call in symbian. The article explains how to get remote party phone number in S60 2nd edition as well as S60 3rd edition devices. Class CTelephony introduced in symbian from S60 2nd edition FP3 onwards, so you can use second method (described in article) to get caller number in a device supporting SDK from S60 2nd edition FP3 onwards.
This is a basic article and the reader my find it easy to implement source code directly. The article contained information which is hard to find, specially for beginners. Personally i tested code for Pre S60 3rd Edition and S60 3rd Edition and its working fine.