Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

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

 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZseriesE5f60Q
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX