Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.
Adding a Contact Item
The following example shows how to create a new contact, add suitable fields, and add the contact to the database. In this example, three text fields with fieldtypes, text labels, and text values are added to a contact. Note that whenever a field is added to a contact, the contact becomes responsible for managing the memory and other resources associated with the field. Therefore, it is not necessary to delete these fields explicitly – popping them from the cleanup stack is sufficient.
Header file required:
CContactDatabase link against library cntmodel.lib , so add following line to your .mmp file.
Add following files in .cpp file.
// Some literal strings for the fields:
// Open the default contacts database:
CContactDatabase* contactsDb = CContactDatabase::OpenL();
// Create a contact card and add some fields:
CContactItem* contact = CContactCard::NewLC();
CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName);
field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldPhoneNumber);
// Add the new contact to the database and set it as the own card:
CleanupStack::PopAndDestroy(2); // contact contactsDb
The contact card that represents the electronic business card of the owner of the Symbian mobile phone can be set by calling the CContactDatabase::SetOwnCardL() function. Note that the CContactItemField::SetMapping() function is called for each of the fields created earlier. This function associates a field with one of the standard vCard fields and is required if the contact will be populated from or will generate a vCard. This mapping is also needed if the application developer wants the contact to be displayed in the Phonebook application.