于Symbian OS的通讯录操作总结
2010-05-31 20:12:00 来源:WEB开发网field->SetMapping(KUidContactFieldVCardMapUnusedN);
//建立与vCard的映射
field->SetLabelL(KSurnameLabel);//设置字段标签
field->TextStorage()->SetTextL(KSurname);//设置字段值
contact->AddFieldL(*field);//把该字段加入到记录中
CleanupStack::Pop();
//添加givenname字段
field=CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
field->SetMapping(KUidContactFieldVCardMapUnusedN);
field->SetLabelL(KForenameLabel);
field->TextStorage()->SetTextL(KForename);
contact->AddFieldL(*field);
CleanupStack::Pop();
//添加phonenumber字段
field=CContactItemField::NewLC(KStorageTypeText, KUidContactFieldPhoneNumber);
field->SetMapping(KUidContactFieldVCardMapTEL);
field->SetLabelL(KWorkPhoneLabel);
field->TextStorage()->SetTextL(KWorkPhone);
contact->AddFieldL(*field);
CleanupStack::Pop();
//把建立的新记录添加到数据库中
contactsDb->AddNewContactL(*contact);
contactsDb->SetOwnCardL(*contact);
CleanupStack::PopAndDestroy(2); // contact contactsDb
3、从数据库中读出数据
CContactDatabase* contactsDb = CContactDatabase::OpenL();
CleanupStack::PushL(contactsDb);
// Get the ID of the own card and open the contact:
TContactItemId ownCardId = contactsDb->OwnCardId();
CContactItem* ownCard = contactsDb->ReadContactL(ownCardId);
CleanupStack::PushL(ownCard);
TInt count = ownCard->CardFields().Count();
contactsDb->CloseContactL(ownCard->Id());
CleanupStack::PopAndDestroy(); // ownCard
3、编辑数据库中的记录
ownCard = contactsDb->OpenContactL(ownCardId);
CleanupStack::PushL(ownCard);
更多精彩
赞助商链接