智手移动中文网's Archiver

智手小石头 发表于 2006-5-9 11:01

关于通讯录的读写

通讯录基于一个通信录数据库,数据库中含有一些通信录项。每个通信录项都有一些域,诸如姓名、地址,以及电话号码等。你需要存储手机号码实际上就是在通讯录项中加上一个你需要的域就可以了,这个在Symbian中当然得到了完全的支持。
例如下面的代码:
code:
________________________________________

_LIT(KNameLabel,"Name");
_LIT(KMobileLabel,"Mobile");
_LIT(KName,"Steve");
_LIT(KMobile,"+8613900000000");

// Open the default contacts database:
CContactDatabase* contactsDb = CContactDatabase::OpenL();
CleanupStack::PushL(contactsDb);
// Create a contact card and add some fields:
CContactItem* contact = CContactCard::NewLC();
CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName);

field->SetMapping(KUidContactFieldVCardMapUnusedN);
field->SetLabelL(KNameLabel);
field->TextStorage()->SetTextL(KName);
contact->AddFieldL(*field);
CleanupStack::Pop();
field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldPhoneNumber);
field->SetMapping(KUidContactFieldVCardMapTEL);
field->SetLabelL(KMobileLabel);
field->TextStorage()->SetTextL(KMobile);
contact->AddFieldL(*field);
CleanupStack::Pop();

// Add the new contact to the database and set it as the own card:
contactsDb->AddNewContactL(*contact);
contactsDb->SetOwnCardL(*contact);
CleanupStack::PopAndDestroy(2); // contact contactsDb

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.