How can I programmatically add contact information with subfields such as "Street (home) on Symbian?
Article Metadata
Compatibility
S60 2nd Edition and FP1, FP2, and FP3
S60 3rd Edition
Article
Overview
How can I programmatically add contact information with subfields such as "Street (home)"?
Description
My application manages the contact fields by using the vCard UIDs of the respective fields (TFieldType in cntdef.h). Everything works fine, except for the field "Street (home)", which once added, appears to be in the field "Address (home)".
Solution:
Unlike normal fields, "Street (home)" is a subfield of "Address (home)". This needs two levels of vCard mapping for adding the information to the correct field.
Below is a simplified code example for doing this:
//-------------------------------------------------------
CContactDatabase* contactsDb = CContactDatabase::OpenL();
CleanupStack::PushL(contactsDb);
CContactItem* contact = CContactCard::NewLC();
CContactItemFieldSet* fieldset = CContactItemFieldSet::NewLC();
CContactItemField* field =
CContactItemField::NewLC(KStorageTypeText,
KUidContactFieldAddress); // VCardUID for address field
field->SetMapping(KUidContactFieldVCardMapADR); // VCardUID for street field type
field->AddFieldTypeL(KUidContactFieldVCardMapHOME); // VCardUID for home field type
field->TextStorage()->SetTextL(KStreetname);
fieldset->AddL(*field);
contact->UpdateFieldSet(fieldset);
CleanupStack::Pop(2); // field, fieldset
contactsDb->AddNewContactL(*contact);
CleanupStack::PopAndDestroy(2); // contact, contactsDb
//-------------------------------------------------------


(no comments yet)