symbian名片夹里添加联系人信息的问题
我自己写了几个函数实现添加联系人和读取联系人信息的功能,需要的信息主要有姓名、手机、家庭固定电话、工作固定电话、职位……内容,现在已经能够够实现将所有内容写入名片夹中,而且在写完之后直接读是没有问题的,但是当后来再调用读取联系人信息的程序读取时,职位跟工作固定电话的内容却无法读取出来,实在搞不懂是怎么回事了哦~~
添加联系人信息的代码:
{
CContactDatabase* contactsDb = CContactDatabase::OpenL();
CleanupStack::PushL(contactsDb);
CContactItem* newItem = contactsDb->CreateOwnCardL();
CleanupStack::PushL(newItem);
TInt fieldIndex = newItem->CardFields().Find(KUidContactFieldVCardMapWORK);
if(fieldIndex != -1)
{
newItem->CardFields()[fieldIndex].TextStorage()->SetTextL(*tempValue);
TBuf<XF_MAX_ADDRESSBOOKITEM_LEN> temptName;
temptName = modifiableItem->CardFields()[fieldIndex].TextStorage()->Text().Left(11); //temptName可以正确读出
}
TContactItemId contactId = contactsDb->AddNewContactL(*newItem);
contactsDb->CloseContactL(contactId);
CleanupStack::PopAndDestroy();//newItem
CleanupStack::PopAndDestroy();//contactsDb
return contactId;
}
{
CContactDatabase* contactsDb = CContactDatabase::OpenL();
CleanupStack::PushL(contactsDb);
CContactItem* card = contactsDb->ReadContactL(contactId);
CleanupStack::PushL(card);
TInt location = card->CardFields().Find(KUidContactFieldVCardMapWORK);
if(location != KErrNotFound)
{
workNumber = card->CardFields()[location].TextStorage()->Text().Left(11);
}
contactsDb->CloseContactL(card->Id());
CleanupStack::PopAndDestroy(); // card
CleanupStack::PopAndDestroy(); // contactsDb
}
{
CContactDatabase* contactsDb = CContactDatabase::OpenL();
CleanupStack::PushL(contactsDb);
// Create a contact card and add some fields:
CContactItem* contact = CContactCard::NewLC();
CContactItemField* field = CContactItemField::NewLC(KStorageTypeText);
field->AddFieldTypeL(KUidContactFieldPhoneNumber); //插入工作固定电话需要两个field type值
field->SetMapping(KUidContactFieldVCardMapTEL);
field->AddFieldTypeL(KIntContactFieldVCardMapWORK);
field->SetMapping(KUidContactFieldVCardMapTEL);
field->TextStorage()->SetTextL(*tempValue);
contact->AddFieldL(*field);
CleanupStack::PopAndDestroy(2);
}
{
CContactDatabase* contactsDb = CContactDatabase::OpenL();
CleanupStack::PushL(contactsDb);
// Create a contact card and add some fields:
CContactItem* contact = CContactCard::NewLC();
CContactItemField* field = CContactItemField::NewLC(KStorageTypeText);
field->AddFieldTypeL(KUidContactFieldJobTitle);
field->SetMapping(KUidContactFieldVCardMapTITLE);
field->TextStorage()->SetTextL(*tempValue);
contact->AddFieldL(*field);
CleanupStack::PopAndDestroy(2);
}
{
// Add the new contact to the database and set it as the own card:
TContactItemId contactId = contactsDb->AddNewContactL(*contact);
contactsDb->SetOwnCardL(*contact);
contactsDb->CloseContactL(contactId);
}