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.
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.
have you tried searching in wiki http://wiki.forum.nokia.com/index.ph...fault_database
I once had quite similar need,
have done this caller's (full) name getter for a (calling) number:
There are better ways for comparison the numbers, but this does its job, handles also international number format.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; }
Hope it helps.
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.
11 could be too much for most of the countries, I would go with 8-9..
I had some sort of problem with this first, maybe because digit amount, but now works very well, thanks!
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.