Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.
Search phone number in phonebook
The class CContactDatabase provides MatchPhoneNumberL method to search for phone numbers in telephone, fax or SMS type fields of phonebook contact item.
This is useful in telephony applications to find the presence of an incoming call phone number in the contacts.
The following code snippet searches for the given phone number and displays all the fields information of all the contacts matched.
// phone number to search
// Opens the default contact database
iContactsDb = CContactDatabase::OpenL();
// Search for all phonebook items matching phone number
// Count of matchings found
CEikonEnv::InfoWinL(_L("Count of Matches"),callNameBuf);
// Reading matched contacts info
for(TInt i = 0;i < iMyIdArray->Count();i++)
TContactItemId id = (*iMyIdArray)[i];
// Read contact using id
CContactItem* contact = iContactsDb->ReadContactL(id);
// Get a reference to the contact item's field set
CContactItemFieldSet& fieldSet = contact->CardFields();
// Read and display all fields
for ( TInt j = 0 ; j < fieldSet.Count() ; j++ )
const CContactItemField& field = fieldSet[j] ;
// phone numbers are stored in database using text fields
NOTE: The comparison method used is not exact. The number is compared starting from the right side of the number and the method returns an array of candidate matches.It is recommended that at least 7 match digits are specified even when matching a number containing fewer digits. Punctuation (eg. spaces) and other alphabetic characters are ignored when comparing.So the search will be successful even if phone number has spaces.
_LIT(KToken,"+9199 083 44484"); // phone number with spaces