当前位置:编程学习 > wap >>

Symbian 关于联系人读取和CPbkContactEngine的使用问题

    最近在做一个读取联系人的程序,出现了一些奇怪的问题!先贴代码
 void CBluetoothFDQContainerView::ExportPhonebook()
        {
        CContactDatabase * p_base = CContactDatabase::OpenL();
        CleanupStack::PushL(p_base);

        TContactIter it(*p_base);
        TContactItemId item_id;

        TBuf<128> tempBuf;
        TBuf8<128> buf8;

        TInt err;
        RFile file;
        err = file.Replace(CCoeEnv::Static()->FsSession(), KFileName, EFileWrite);

        CleanupClosePushL(file);
        if (KErrNone != err)
                {
                CleanupStack::PopAndDestroy(1); // file
                return;
                }

        while ((item_id = it.NextL()) != KNullContactId)
                {
                CContactItem * p_item = p_base->ReadContactL(item_id);
                CleanupStack::PushL(p_item);

                tempBuf.Zero();
                tempBuf.Append(_L("<Item>"));

                TInt i_fname = p_item->CardFields().Find(KUidContactFieldFamilyName);//��  1
                if (i_fname != KErrNotFound)
                        {
                        TPtrC16 p_str_fname =
                                        p_item->CardFields()[i_fname].TextStorage()->Text();
                        tempBuf.Append(_L("<fname>"));
                        tempBuf.Append(p_str_fname);
                        //CEikonEnv::Static()->InfoWinL(_L("fname"),p_str_fname);
                        tempBuf.Append(_L("</fname>"));
                        }
                buf8.Delete(0, buf8.Length());
                CnvUtfConverter::ConvertFromUnicodeToUtf8(buf8, tempBuf);
                file.Write(buf8);
                tempBuf.Delete(0, tempBuf.Length());

                TInt i_name = p_item->CardFields().Find(KUidContactFieldGivenName);//��  2
                if (i_name != KErrNotFound)
                        {
                        TPtrC16 p_str_name =
                                        p_item->CardFields()[i_name].TextStorage()->Text();
                        tempBuf.Append(_L("<gname>"));
                        tempBuf.Append(p_str_name);
                        tempBuf.Append(_L("</gname>"));
                        }
                buf8.Delete(0, buf8.Length());
                CnvUtfConverter::ConvertFromUnicodeToUtf8(buf8, tempBuf);
                file.Write(buf8);
                tempBuf.Delete(0, tempBuf.Length());

                TInt i_phone = p_item->CardFields().Find(KUidContactFieldPhoneNumber);//�ֻ�  3
                if (i_phone != KErrNotFound)
                        {

                        TPtrC p_str_phone =
                                        p_item->CardFields()[i_phone].TextStorage()->Text();

                        tempBuf.Append(_L("<phone>"));
                        tempBuf.Append(p_str_phone);
                        tempBuf.Append(_L("</phone>"));
                        }
                buf8.Delete(0, buf8.Length());
                CnvUtfConverter::ConvertFromUnicodeToUtf8(buf8, tempBuf);
                file.Write(buf8);
                tempBuf.Delete(0, tempBuf.Length());

                TInt i_country = p_item->CardFields().Find(KUidContactFieldCountry);//    4
                if (i_country != KErrNotFound)
                        {
                        TPtrC p_str_country =
                                        p_item->CardFields()[i_country].TextStorage()->Text();
                        tempBuf.Append(_L("<country>"));
                        tempBuf.Append(p_str_country);
                        tempBuf.Append(_L("</country>"));
                        }
                buf8.Delete(0, buf8.Length());
                CnvUtfConverter::ConvertFromUnicodeToUtf8(buf8, tempBuf);
                file.Write(buf8);
                tempBuf.Delete(0, tempBuf.Length());

                TInt i_company = p_item->CardFields().Find(KUidContactFieldCompanyName);//��˾  5
                if (i_company != KErrNotFound)
                        {
                        TPtrC p_str_company =
                                        p_item->CardFields()[i_company].TextStorage()->Text();
                        tempBuf.Append(_L("<company>"));
                        tempBuf.Append(p_str_company);
                        tempBuf.Append(_L("</company>"));
                        }
                buf8.Delete(0, buf8.Length());
                CnvUtfConverter::ConvertFromUnicodeToUtf8(buf8, tempBuf);
                file.Write(buf8);
                tempBuf.Delete(0, tempBuf.Length());

                TInt i_email = p_item->CardFields().Find(KUidContactFieldEMail);//��������  7
                if (i_email != KErrNotFound)
                        {
                        TPtrC p_str_email =
                                        p_item->CardFields()[i_email].TextStorage()->Text();
                        tempBuf.Append(_L("<email>"));
                        tempBuf.Append(p_str_email);
                        tempBuf.Append(_L("</email>"));
                        }
                buf8.Delete(0, buf8.Length());
                CnvUtfConverter::ConvertFromUnicodeToUtf8(buf8, tempBuf);
                file.Write(buf8);
                tempBuf.Delete(0, tempBuf.Length());

                TInt i_postOffice = p_item->CardFields().Find(
                                KUidContactFieldPostOffice);//��������      8
                if (i_postOffice != KErrNotFound)
                        {
                        TPtrC p_str_postoffice =
                                        p_item->CardFields()[i_postOffice].TextStorage()->Text();
                        tempBuf.Append(_L("<postoffice>"));
                        tempBuf.Append(p_str_postoffice);
                        tempBuf.Append(_L("</postoffice>"));
                        }
                buf8.Delete(0, buf8.Length());
                CnvUtfConverter::ConvertFromUnicodeToUtf8(buf8, tempBuf);
                file.Write(buf8);
                tempBuf.Delete(0, tempBuf.Length());

                TInt i_region = p_item->CardFields().Find(KUidContactFieldRegion);//ʡ����     9
                if (i_region != KErrNotFound)
                        {
                        TPtrC p_str_country =
                                        p_item->CardFields()[i_region].TextStorage()->Text();
                        tempBuf.Append(_L("<region>"));
                        tempBuf.Append(p_str_country);
                        tempBuf.Append(_L("</region>"));
                        }
                buf8.Delete(0, buf8.Length());
                CnvUtfConverter::ConvertFromUnicodeToUtf8(buf8, tempBuf);
                file.Write(buf8);
                tempBuf.Delete(0, tempBuf.Length());

                TInt i_extendedAddr = p_item->CardFields().Find(
                                KUidContactFieldExtendedAddress);//��ϸ��ַ        10ַ
                if (i_extendedAddr != KErrNotFound)
                        {
                        TPtrC p_str_extendedAddr =
                                        p_item->CardFields()[i_extendedAddr].TextStorage()->Text();
                        tempBuf.Append(_L("<extendedAddr>"));
                        tempBuf.Append(p_str_extendedAddr);
                        tempBuf.Append(_L("</extendedAddr>"));
                        }
                buf8.Delete(0, buf8.Length());
                CnvUtfConverter::ConvertFromUnicodeToUtf8(buf8, tempBuf);
                file.Write(buf8);
                tempBuf.Delete(0, tempBuf.Length());

                tempBuf.Append(_L("</Item>"));
                buf8.Delete(0, buf8.Length());
                CnvUtfConverter::ConvertFromUnicodeToUtf8(buf8, tempBuf);
                file.Write(buf8);
                tempBuf.Delete(0, tempBuf.Length());

                p_base->CloseContactL(p_item->Id());
                CleanupStack::PopAndDestroy(p_item);
                }
        CleanupStack::PopAndDestroy(2);

        }

在对应的姓的域内读出一些奇奇怪怪的记录(例f39a0e3aa9facd0cffeb78dfafe37dfff7fbfedf41302d8d5fb6fb0bfad69658)!用E66测试是出现在最前面的两条, 5320 是出现在中间的两条,而N73的话就是第一条出现错误记录


改用CPbkContactEngine来实现的话,用该类的NewL方法老是new不成功,换用Static得到的却是NULL



有哪位大牛能帮帮我
补充:移动开发 ,  Symbian
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,