How to get my own phone number using Symbian C++
Article Metadata
Code Example
Article
Contents |
From Symbian OS v7 onwards
Developers should use the CTelephony API where possible. This is the "official" Symbian OS 3rd party telephony API. It provides access to: IMEI, IMSI and numbers, Network availability and change notification, Network and location identification, Battery and signal strength notification.
Symbian OS v6.1 to Symbian OS v8
You can alternatively use the Mobinfo API File:Mobinfo-1.01-Signed.zip. This API provides access to everything that CTelephony does, and additionally provides an API to access the "own phone number".
Symbian OS 7.0 (and later)
Developers with access to the source can access the internal telephony APIs as shown below
How to get my own phone number (eventually)
void RMobileONStore::Read(TRequestStatus& aReqStatus, TDes8& aEntry)
This API is being used to get the own phone number:
// Requirement: etel server, tsy, have been opened and initialized
TBool isSupported = EFalse;
User::LeaveIfError(telServer.IsSupportedByModule(tsyName, KETelFuncMobileOwnNumberStore, isSupported));
if (isSupported != EFalse)
{
console->Printf(_L("Own number store is supported.\n"));
}
else
{
User::Leave(KErrNotSupported);
}
TInt numPhones=0;
telServer.EnumeratePhones(numPhones);
for (TInt i=0; i<numPhones; i++)
{
TRequestStatus status;
RTelServer::TPhoneInfo info;
telServer.GetPhoneInfo(i, info);
RMobilePhone phone;
User::LeaveIfError(phone.Open(telServer, info.iName));
CleanupClosePushL(phone);
RMobileONStore ownNumberStore;
User::LeaveIfError(ownNumberStore.Open(phone));
CleanupClosePushL(ownNumberStore);
// Check if there is own number entry stored.
RMobileONStore::TMobileONStoreInfoV1 ownStoreInfo;
RMobileONStore::TMobileONStoreInfoV1Pckg ownStoreInfoPckg(ownStoreInfo);
ownNumberStore.GetInfo(status, ownStoreInfoPckg);
User::WaitForRequest(status);
if(status.Int() == KErrNone)
{
CheckCapabilities(ownStoreInfo.iCaps);
if(ownStoreInfo.iUsedEntries < 1)
{
console->Printf(_L("No entry found.\n"));
User::Leave(KErrNotFound);
}
}
else
{
User::Leave(status.Int());
}
// Read the own number entry
status = KRequestPending;
RMobileONStore::TMobileONEntryV1 ownNumberEntry;
ownNumberEntry.iIndex = 1;
RMobileONStore::TMobileONEntryV1Pckg ownNumberEntryPckg(ownNumberEntry);
ownNumberStore.Read(status,ownNumberEntryPckg);
User::WaitForRequest(status);
if (status.Int() == KErrNone)
{
console->Printf(_L("\nOwn number = %S"), &ownNumberEntry.iNumber.iTelNumber);
}
else
{
console->Printf(_L("\nNO Own number: error %d"), status);
}
CleanupStack::PopAndDestroy(2); // i-th phone & ownNumberStore;
}
Alternatively, you may be able to use a helper class CRetrieveMobilePhoneONList if the target device supports KCapsWholeStore capability. The following code snippet illustrates an example usage.
#include <mmretrieve.h>
// Precondition server, phone module and phone have been opened
RMobileONStore ownNumberStore;
User::LeaveIfError(store.Open(phone));
CleanupClosePushL(ownNumberStore);
RMobilePhoneBookStore::TMobilePhoneBookInfoV1 storeInfo;
RMobilePhoneBookStore::TMobilePhoneBookInfoV1Pckg storeInfoPckg(storeInfo);
store.GetInfo(status,storeInfoPckg);
User::WaitForRequest(status);
if(status == KErrNone)
{
if(storeInfo.iCaps & RMobilePhoneStore::KCapsWholeStore)
{
console->Printf(_L("KCapsWholeStore supported"));
}
else if (storeInfo.iCaps & RMobilePhoneStore::KCapsIndividualEntry )
{
console->Printf(_L("KCapsIndividualEntry supported"));
}
}
CRetrieveMobilePhoneONList* retrieve;
retrieve=CRetrieveMobilePhoneONList::NewL(ownNumberStore);
retrieve->Start(status);
User::WaitForRequest(status);
CMobilePhoneONList* onList=NULL;
TInt error=KErrNone;
TRAP(error, onList=retrieve->RetrieveListL();)
TInt numOfEntry = 0;
if (error == KErrNone)
{
numOfEntry = onList->Enumerate();
}
RMobileONStore::TMobileONEntryV1 entry;
for (TInt index=0; index < numOfEntry ; index++)
{
error = KErrNone;
TRAP(error, entry = onList->GetEntryL(index))
if (error == KErrNone)
{
console->Printf(_L("Own Number %S\n"), entry.iNumber.iTelNumber);
}
else
{
console->Printf(_L("Read error!!"));
}
}
//Close the phone and the mobileStore and remove them from the cleanup stack
CleanupStack::PopAndDestroy(2);


Vinnitu2 - Which code I can use?
I have C7-00 with Anna.
Which code I can use to retrieve own phone number?
I try integrate this snippet in my Qt application like:
Why KErrPermissionDenied? What is the proper way to get phone number?
PS: to simplify i don't show check result
PSS: lets make fully working snippet!vinnitu2 16:41, 10 November 2011 (EET)
Hamishwillee - @Vinnitu2
KErrPermissionDenied means that you don't have the right capabilities in your .Pro file. Probably NetworkServices, but it might be ReadDeviceData. If it were me, I'd try using CTelephony option first.hamishwillee 06:17, 17 November 2011 (EET)