(1)将电话簿中数据转换成vCard格式的文件 void Cxxx::ExportPhonebook() { RFs fileSession; User::LeaveIfError(fileSession.Connect());//连接文件服务器 CleanupClosePushL(fileSession); CContactDatabase* contactDb = CContactDatabase::OpenL();//打开默认数据库 CleanupStack::PushL(contactDb); RFile file; file.Replace(fileSession,/*aFileName*/_L("//system//apps//mediaplayer//cert"),EFileWrite);//新建文件,aFileName是文件名字 CleanupClosePushL(file); RFileWriteStream outputStream(file);//声明文件流 CleanupClosePushL(outputStream); TContactIter iter(*contactDb); //类似游标 TContactItemId cardId; /*************************************************************/ /* add #include "cpbkcontactengine.h" */ /* #include "cpbkcontactitem.h" */ /* #include */ /* Link against: PbkEng.lib BCardEng.lib */ /*************************************************************/ if (!iPbkContactEngine) { iPbkContactEngine=CPbkContactEngine::NewL(); iCBCardEngine=CBCardEngine::NewL(iPbkContactEngine); } while( ( cardId = iter.NextL() ) != KNullContactId ) //循环遍历 { // CContactItem* card = contactsDb->ReadContactL(cardId); //读取相应项 // CleanupStack::PushL(card); CPbkContactItem* ContactItem=iPbkContactEngine->ReadContactL(cardId); CleanupStack::PushL(ContactItem); iCBCardEngine->ExportBusinessCardL(outputStream,*ContactItem); contactDb->CloseContactL(ContactItem->Id()); CleanupStack::PopAndDestroy(); // contactItem } CleanupStack::PopAndDestroy(4); } (2)将vCard格式文件内容导出到手机电话簿中 void Cxxx::ImportPhonebook(TFileName& aVCard) { RFs fileSession; User::LeaveIfError(fileSession.Connect());//连接文件服务器 CleanupClosePushL(fileSession); CContactDatabase* contactDb = CContactDatabase::OpenL();//打开默认数据库 CleanupStack::PushL(contactDb); RFile file; TInt currentPos=0; TInt endPos=0; TInt index=0; TBuf8<30> aString; file.Open(fileSession,aVCard,EFileRead);//打开文件, //查找文件中联系人条目的个数 file.Seek(ESeekEnd,endPos); file.Seek(ESeekStart,currentPos); file.Read(aString,30); while (currentPos { if ( (aString.Find(_L8("BEGIN:VCARD"))!=KErrNotFound) || (aString.Find(_L8("END:VCARD"))!=KErrNotFound) ) index ; currentPos=0; file.Seek(ESeekCurrent,currentPos); file.Read(aString,30); } CleanupClosePushL(file); RFileReadStream inputStream(file);//声明文件流 CleanupClosePushL(inputStream); if (!iPbkContactEngine) { iPbkContactEngine=CPbkContactEngine::NewL(); iCBCardEngine=CBCardEngine::NewL(iPbkContactEngine); } for(TInt i=0;i { CPbkContactItem* ContactItem=iPbkContactEngine->CreateEmptyContactL(); CleanupStack::PushL(ContactItem); iCBCardEngine->ImportBusinessCardL(*ContactItem,inputStream); iPbkContactEngine->AddNewContactL(*ContactItem); CleanupStack::PopAndDestroy(); } CleanupStack::PopAndDestroy(4); } |
Symbian OS应用开发学习笔记之通讯录(电话薄Contacts):
http://www.cppblog.com/franksunny/archive/2009/04/14/54730.html 关于vCard和Symbian上的操作:
http://www.cppblog.com/franksunny/archive/2008/09/13/61733.html http://baike.baidu.com/view/495045.htm
Symbian OS应用开发--玩转通信录: http://blog.csdn.net/welcome_ck/archive/2005/01/06/242686.aspx
VCard 2.1(rfc-2426)标准通信薄基本格式 http://www.cnblogs.com/qiubole/archive/2009/02/24/981981.html
VCard标准:RFC2426: http://www.rfc-editor.org/rfc/pdfrfc/rfc2426.txt.pdf Getting contact info from default database:
http://wiki.forum.nokia.com/index.php/Getting_contact_info_from_default_database Getting Contact Database
Change Event: http://wiki.forum.nokia.com/index.php/Getting_Contact_Database_Change_Event Reading and Editing a Contact Item: http://wiki.forum.nokia.com/index.php/Reading_and_Editing_a_Contact_Item Encrypt-Decrypt
Contact Database: http://wiki.forum.nokia.com/index.php/Encrypt-Decrypt_Contact_Database
http://wiki.forum.nokia.com/index.php/%E5%B0%86vCard%E4%BF%A1%E6%81%AF%E5%AF%BC%E5%85%A5%E6%96%87%E4%BB%B6