Categories: S60 | Symbian C++ | PIM | Code Examples
This page was last modified 05:49, 20 November 2007.
Search phone number in phonebook
From Forum Nokia Wiki
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.
Header Files:
#include <CNTFLDST.H> #include <CNTITEM.H>
Link against:
LIBRARY cntmodel.lib
Capabilities Required:
CAPABILITY ReadUserData
void SearchPhoneNumber() { // phone number to search _LIT(KToken,"+919908344484"); TBuf<128> callNameBuf; // Opens the default contact database iContactsDb = CContactDatabase::OpenL(); // Search for all phonebook items matching phone number iMyIdArray= iContactsDb->MatchPhoneNumberL(KToken,10); // Count of matchings found callNameBuf.AppendNum(iMyIdArray->Count()); 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); CleanupStack::PushL(contact); // 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 callNameBuf.Copy(field.TextStorage()->Text()); CEikonEnv::InfoWinL(callNameBuf,field.Label()); } CleanupStack::PopAndDestroy(); } }
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 iMyIdArray= iContactsDb->MatchPhoneNumberL(KToken,15);
Code Example
An example application to search phone number in phonebook
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| CPbkEmailAddressSelect / integrating Contacts (or Phonebook) | jknepper | General Symbian C++ | 3 | 2007-05-04 14:30 |
| How can i retrieve my phone number? | dhanyap | Mobile Java Networking & Messaging & Security | 3 | 2007-03-07 06:03 |
| read write modify phonebook entries of Nokia 6310i | tixoman | PC Suite API and PC Connectivity SDK | 0 | 2002-12-13 09:22 |
| midlet version number on Series 60 | barnabyg | Series 40 & S60 Platform Feedback | 1 | 2006-10-24 16:19 |
| How to edit phone entries (Phonebook-Calendar) directly from PC ? | johnanast | Bluetooth Technology | 1 | 2004-07-15 10:54 |
