Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User rajeshpadhiary's Avatar
    Join Date
    Aug 2008
    Posts
    18
    hi, in my applications when user dial a number it will search the contact database and display the name instead of number.can any one help out as i have try this using all the API in series 60,but it can't access the contactdatabase.plz help me out.

  2. #2
    Nokia Developer Moderator skumar_rao's Avatar
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

  3. #3
    Regular Contributor Jii5Hoo's Avatar
    Join Date
    Jan 2008
    Posts
    56
    I once had quite similar need,
    have done this caller's (full) name getter for a (calling) number:

    Code:
    HBufC8* GetCallerNameL( TDesC8& aNumber )
        {
        TBuf<128> callernumber;
        callernumber.Copy( aNumber );
    
        CContactDatabase* contactsDb = CContactDatabase::OpenL();
        CleanupStack::PushL(contactsDb);
    
        TContactIter iter(*contactsDb);
        TContactItemId cardId;
    
        // Go through all
        while( ( cardId = iter.NextL() ) != KNullContactId )
            {
            CContactItem* card = contactsDb->ReadContactL(cardId);
            CleanupStack::PushL(card);
    
            // Search for number
            TInt number = card->CardFields().Find(KUidContactFieldPhoneNumber);
    
            if( number != KErrNotFound )
                {
                TPtrC contactnumberPtr = card->CardFields()[number].TextStorage()->Text();
                TInt contactnumberPos = contactnumberPtr.Length()-1;
                TInt callernumberPos = callernumber.Length()-1;
    
                while( (contactnumberPtr[contactnumberPos] == callernumber[callernumberPos]) && 
                       (contactnumberPos > 0) && (callernumberPos > 0) )
                    {
                    contactnumberPos--;
                    callernumberPos--;
                    };
                TBool found(EFalse);
    
                if( (contactnumberPtr[0] == '+') ||
                    (callernumber[0] == '+' ) )
                    {
                    if( callernumberPos < 4 )
                        {
                        found = ETrue;
                        }
                    }
                else if( callernumberPos == 0 )
                    {
                    found = ETrue;
                    }
    
                if( found )
                    {
                    TInt firstName = card->CardFields().Find(KUidContactFieldGivenName);
                    TInt lastName = card->CardFields().Find(KUidContactFieldFamilyName);
    
                    if( firstName != KErrNotFound )
                        {
                        TPtrC fName = card->CardFields()[firstName].TextStorage()->Text();
                        TPtrC lName;
                        if( lastName != KErrNotFound )
                            {
                            lName.Set( card->CardFields()[lastName].TextStorage()->Text() );
                            }
                        HBufC8* fullname = HBufC8::NewLC( fName.Length()+1+lName.Length() );
    
                        fullname->Des().Copy( fName );
                        fullname->Des().Append( _L8(" ") );
                        HBufC8* lastname8 = HBufC8::NewL( lName.Length() );
                        lastname8->Des().Copy( lName );
                        fullname->Des().Append( *lastname8 );
                        delete lastname8;
    
                        CleanupStack::Pop();
                        CleanupStack::PopAndDestroy(2);
    
                        return fullname;
                        }
                    }
                }
            else
                {
                .. will return NULL
                }
    
            contactsDb->CloseContactL(card->Id());
    
            CleanupStack::PopAndDestroy(); // card
            }
    
        CleanupStack::PopAndDestroy(); // contactsDb
    
        return NULL;
        }
    There are better ways for comparison the numbers, but this does its job, handles also international number format.

    Hope it helps.

  4. #4
    Registered User vaibhavjain's Avatar
    Join Date
    Jan 2007
    Posts
    282
    I think CContactDatabase::MatchPhoneNumberL is a better way to match phone number and it will do the mentioned purpose.

    Simply pass it the descriptor containing the number and the number of digits to match (usually value of 11 does fine) and it resturn the matching contacts for that number.

    Best thing aboute it is that it matches against all the contact fields that are marked as containing phone numbers (sms/fax/mobile etc) and also handles special number format like

    123-123-123-123 matches against +123123123 123 and various permutations.

    hope that helps.

  5. #5
    Nokia Developer Expert symbianyucca's Avatar
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    28,664
    11 could be too much for most of the countries, I would go with 8-9..

  6. #6
    Regular Contributor Jii5Hoo's Avatar
    Join Date
    Jan 2008
    Posts
    56
    I had some sort of problem with this first, maybe because digit amount, but now works very well, thanks!

  7. #7
    Regular Contributor raysky's Avatar
    Join Date
    Mar 2003
    Posts
    131
    any of u knows how i can differentiate teh type of number i get from the API?

    for example is it belongs to KuidContactFieldVCardMapTEL
    and KUidContactFieldVCardMapCELL for it to appear under "Mobile" category

    or something else.....

    hmm...managed to do it this way...
    Code:
    				while((findpos > -1) && (findpos <= fieldSet.Count()))
    					{
    					findpos=fieldSet.FindNext( KUidContactFieldPhoneNumber,KUidContactFieldVCardMapTEL,findpos+pos );
    					// Check that the phone no field is actually there.
    					if ( (findpos > -1) && (findpos <= fieldSet.Count()) )
    						{
    						CContactItemField& NumField = fieldSet[findpos];
    						if(NumField.ContentType().ContainsFieldType(KUidContactFieldVCardMapCELL))
    							{
    							PhoneNo = NumField.TextStorage()->Text().AllocLC();
    							_LIT(KSpaceDes," ");
    							TInt bufLen = (PhoneNo->Length()-1);
    							TInt sq=0;
    							while (sq <= bufLen)
    								{
    								if (PhoneNo->Des().Mid(sq,1) == KSpaceDes)
    									{
    									PhoneNo->Des().Delete(sq,1);
    									bufLen--;
    									}
    								else
    									sq++;
    								}
    							PhoneNumbers.Insert(PhoneNo,PhoneNumbers.Count());
    							pos=1;
    							}
    						}
    					}

    anyone knows how to create the "nickname" field in the contact?

    didnt seem to work with this code here:
    Code:
    field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldSecondName);
    field->SetMapping(KUidContactFieldVCardMapUnusedFN);
    field->TextStorage()->SetTextL(nick);
    item->AddFieldL(*field);
    CleanupStack::Pop();
    Last edited by raysky; 2008-09-09 at 04:26.

Similar Threads

  1. Retrieving Phone Number from Contacts database
    By dick_matthews in forum Symbian C++
    Replies: 5
    Last Post: 2009-03-16, 06:37
  2. how to update the contact ids of contact database
    By navmittal in forum Symbian C++
    Replies: 1
    Last Post: 2008-01-25, 10:34
  3. contact number and contact names doesn't match.
    By ninidotnet in forum Symbian User Interface
    Replies: 0
    Last Post: 2006-10-09, 09:25
  4. WML & WMLSCript problem ????
    By gemini_shooter in forum Browsing and Mark-ups
    Replies: 0
    Last Post: 2006-01-14, 06:01
  5. creating a Contact with more than one Number
    By lpinguin in forum Mobile Java General
    Replies: 0
    Last Post: 2005-07-25, 17:33

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved