Sysbian SDK有个文档是Using_Symbian_Contacts_Model.pdf 里面有很多通讯录的操作,例如上面有添加通讯录条目的例子,可以添加到数据库里面,但是用我的方法添加的数据用程序读取不到,是个很郁闷人的问题,在网上找到了Series_60_Developer_Platform_1_0_2_0_Using_the_Phone_Book_Engine_v1_0_en.pdf文档 ,用上面的添加方法就添加的数据就可以找到,下面是用文档里面介绍的方法的一个对照说明:感谢a14776584 嘿嘿 有很大帮助
void InsertContactItemL()
{
CPbkContactEngine * engine = CPbkContactEngine::NewL();
CleanupStack::PushL(engine);
CPbkContactItem* contact = engine->CreateEmptyContactL();//新建一空通信录项
CleanupStack::PushL(contact);
_LIT(KFName,"King");
_LIT(KLName,"Chai");
_LIT(KNumber,"13777777777");
//修改first name
TPbkContactItemField* field = contact->FindField(EPbkFieldIdFirstName);
CPbkFieldInfo* fieldInfo;
field->TextStorage()->SetTextL(KFName);
//修改last name
field = contact->FindField(EPbkFieldIdLastName);
field->TextStorage()->SetTextL(KLName);
//修改手机号码
field = contact->FindField(EPbkFieldIdPhoneNumberMobile); //手机号码
field->TextStorage()->SetTextL(KNumber);
field = contact->FindField(EPbkFieldIdPhoneNumberGeneral); //电话号码
field->TextStorage()->SetTextL(_L("000000"));
field = contact->FindField(EPbkFieldIdPhoneNumberStandard); //电话号码 VCard: TEL;VOICE:111111
field->TextStorage()->SetTextL(_L("111111"));
//
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdPhoneNumberHome); //电话号码(家庭)
contact->AddFieldL(*fieldInfo);
field = contact->FindField(EPbkFieldIdPhoneNumberHome);
field->TextStorage()->SetTextL(_L("222222"));
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdPhoneNumberWork); //电话号码(办公)
contact->AddFieldL(*fieldInfo);
field = contact->FindField(EPbkFieldIdPhoneNumberWork);
field->TextStorage()->SetTextL(_L("333333"));
field = contact->FindField(EPbkFieldIdFaxNumber); //传真
field->TextStorage()->SetTextL(_L("444444"));
field = contact->FindField(EPbkFieldIdPagerNumber); //寻呼机
field->TextStorage()->SetTextL(_L("555555"));
field = contact->FindField(EPbkFieldIdEmailAddress); //电子邮件
field->TextStorage()->SetTextL(_L("666666"));
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdPostalAddress); //地址
contact->AddFieldL(*fieldInfo);
field = contact->FindField(EPbkFieldIdPostalAddress);
field->TextStorage()->SetTextL(_L("777777"));
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdURL); //网址
contact->AddFieldL(*fieldInfo);
field = contact->FindField(EPbkFieldIdURL);
field->TextStorage()->SetTextL(_L("888888"));
field = contact->FindField(EPbkFieldIdJobTitle); //职位
field->TextStorage()->SetTextL(_L("999999"));
field = contact->FindField(EPbkFieldIdCompanyName); //公司
field->TextStorage()->SetTextL(_L("123456"));
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdCompanyAddress); //地址
contact->AddFieldL(*fieldInfo);
field = contact->FindField(EPbkFieldIdCompanyAddress);
field->TextStorage()->SetTextL(_L("789012"));
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdDTMFString);
contact->AddFieldL(*fieldInfo);
field = contact->FindField(EPbkFieldIdDTMFString); //双音多频
field->TextStorage()->SetTextL(_L("909090"));
TDateTime dateTime;
TInt year=1996, month=12, day=31;
dateTime.Set(year,TMonth(month-1),day-1,0,0,0,0);
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdDate);
contact->AddFieldL(*fieldInfo);
field = contact->FindField(EPbkFieldIdDate ); //生日
field->DateTimeStorage()->SetTime(dateTime);
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdNote);
contact->AddFieldL(*fieldInfo);
field = contact->FindField(EPbkFieldIdNote ); //备注
field->TextStorage()->SetTextL(_L("12121212"));
//fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdVoiceTagIndication);
//contact->AddFieldL(*fieldInfo);
//field = contact->FindField(EPbkFieldIdVoiceTagIndication); //
//field->TextStorage()->SetTextL(_L("333333"));
//fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdSpeedDialIndication);
//contact->AddFieldL(*fieldInfo);
//field = contact->FindField( EPbkFieldIdSpeedDialIndication ); //
//field->TextStorage()->SetTextL(_L("444444"));
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdPersonalRingingToneIndication);
contact->AddFieldL(*fieldInfo);
field = contact->FindField(EPbkFieldIdPersonalRingingToneIndication ); //来电铃声
field->TextStorage()->SetTextL(_L("098765"));
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdPOBox);
contact->AddFieldL(*fieldInfo);
field = contact->FindField(EPbkFieldIdPOBox); //邮政信箱
field->TextStorage()->SetTextL(_L("999888"));
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdExtendedAddress);
contact->AddFieldL(*fieldInfo);
field = contact->FindField(EPbkFieldIdExtendedAddress ); //地址详情
field->TextStorage()->SetTextL(_L("999777"));
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdStreetAddress);
contact->AddFieldL(*fieldInfo);
field = contact->FindField(EPbkFieldIdStreetAddress ); //街道
field->TextStorage()->SetTextL(_L("999666"));
//fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdWVID);
//contact->AddFieldL(*fieldInfo);
//field = contact->FindField(EPbkFieldIdWVID ); //
//field->TextStorage()->SetTextL(_L("999555"));
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdSecondName);
contact->AddFieldL(*fieldInfo);
field = contact->FindField(EPbkFieldIdSecondName ); //昵称
field->TextStorage()->SetTextL(_L("999444"));
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdPhoneNumberVideo);
contact->AddFieldL(*fieldInfo);
field = contact->FindField(EPbkFieldIdPhoneNumberVideo ); //可视电话
field->TextStorage()->SetTextL(_L("999000"));
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdPostalCode);
contact->AddFieldL(*fieldInfo);
field = contact->FindField(EPbkFieldIdPostalCode ); //邮政编码
field->TextStorage()->SetTextL(_L("111333"));
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdCity);
contact->AddFieldL(*fieldInfo);
field = contact->FindField(EPbkFieldIdCity); //城市
field->TextStorage()->SetTextL(_L("222333"));
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdState);
contact->AddFieldL(*fieldInfo);
field = contact->FindField( EPbkFieldIdState ); //省/区/县
field->TextStorage()->SetTextL(_L("444333"));
fieldInfo = engine->FieldsInfo().Find(EPbkFieldIdCountry);
contact->AddFieldL(*fieldInfo);
field = contact->FindField(EPbkFieldIdCountry ); //国家或地区
field->TextStorage()->SetTextL(_L("333555"));
TContactItemId Id = engine->AddNewContactL(*contact);//修改后结果添加到数据库中,并返回这个通信录项的id,可以以后使用
CleanupStack::PopAndDestroy(contact);
CleanupStack::PopAndDestroy(engine);
}
//导出的vcard信息
//BEGIN:VCARD
//VERSION:2.1
//REV:20090721T054256Z
//END:VCARD
//BEGIN:VCARD
//VERSION:2.1
//REV:20090721T060823Z
//N:Chai;King;;;
//ADR:999888;999777;999666;222333;444333;111333;333555
//ORG:123456;
//TITLE:999999
// TEL;CELL:13777777777
// TEL;VOICE:111111
// TEL;VIDEO:999000
// TEL;FAX:444444
// TEL;PAGER:555555
// EMAIL;INTERNET:666666
// TEL;VOICE;HOME:222222
// TEL;VOICE;WORK:333333
//LABEL:789012
//URL:888888
//BDAY:19961231
//NOTE:12121212
// X-EPOCSECONDNAME:999444
//END:VCARD
其中EPbkFieldIdVoiceTagIndication,EPbkFieldIdSpeedDialIndication,EPbkFieldIdWVID, engine->FieldsInfo().Find()时返回的是一个空指针;而且上述所列的部分枚举值在s60的名片夹里是重复的项目,显示会相互覆盖,例如:EPbkFieldIdPostalAddress,EPbkFieldIdCompanyAddress等,但是在VCARD的信息表明实际数据是没有覆盖的。
还有部分pbkfields.hrh里的枚举值暂时没有研究,在这里粘贴出来,希望有知道的能告知一二:
#define EPbkFieldIdLastNameReading 0x21
#define EPbkFieldIdFirstNameReading 0x22
#define EPbkFieldIdLocationIdIndication 0x23
#define EPbkFieldIdVOIP 0x24
#define EPbkFieldIdPushToTalk 0x25
#define EPbkFieldIdShareView 0x26
#define EPbkFieldIdSIPID 0x27
#define EPbkFieldIdCodTextID 0x28
#define EPbkFieldIdCodImageID 0x29
#define EPbkFieldIdPrefix 0x30
#define EPbkFieldIdSuffix 0x31
#define KPbkFieldIdMask 0xff
#define EPbkFieldGroupIdNone 0x00
#define EPbkFieldGroupIdPostalAddress 0x01
#define EPbkFieldGroupIdHomeAddress 0x02
#define EPbkFieldGroupIdCompanyAddress 0x03
#define EPbkFieldGroupIdFirstName 0x04
#define EPbkFieldGroupIdLastName 0x05
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/a14776584/archive/2009/07/21/4366744.aspx