Sunday, March 18, 2007

Get Caller Number

Below is the code illustarating how to get the remote party's telephone number. It is different for S60 3rd Edition and previous versions.

In V8 and Below

void GetRemotePartyPhoneNumberL(TDes& aPhoneNumber)
RTelServer etel;

// Connect to ETel server

// Load phone module. This is just to be on the safe side
// because it should have been loaded already
_LIT(KTsyName, "phonetsy.tsy");

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));

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));

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));

RMobileCall::TMobileCallInfoV1 mobCallInfo;
RMobileCall::TMobileCallInfoV1Pckg mobCallInfoPckg(mobCallInfo);

// Get the call's info

// We successfully got the call's info.
// Now copy the remote party's phone number to the target descriptor

// Close all handles
CleanupStack::PopAndDestroy(4); // call, line, phone, etel

In V9 and above
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
callInfoV1Pckg, remotePartyInfoV1Pckg));
// Copy the remote party's phone number to the target descriptor

CleanupStack::PopAndDestroy(); // telephony


vishnu said...

this blog is really very good .. i never seen so informative...
why dont u explain how to modify the TDes variables and displaying on the screen ..
and any of the string variables to display on the screen

Sunil kumar said...

Thanks will post some thing on descriptors soon.

stats counter