zoukankan      html  css  js  c++  java
  • [已解决问题] 总结读取SIM联系人实现(转)

    SIM联系人的读取相对有点麻烦,需要自己添加类库,包含的文件有ETELMM{000a0000}.dso、ETELMM.dso、ETELMM.LIB、etelmm.h、etelmmcs.h、et_clsvr.h altetelmm_uiq3.rar (119.5 KB, 下载次数: 99, 售价: 资源分 2 )
    其中除了最后一个et_clsvr.h自己创建一个头文件,放到inc文件中,其他根据文件的位置放到相应的位置。
            然后相应的修改MMP文件,
            LIBRARY         etel.lib
            LIBRARY                commdb.lib
            LIBRARY     ETELMM.lib。就可以访问RMobilePhoneBookStore类库,调用里面的函数访问到SIM联系人的数据。然而,SIM卡上的通讯录格式是“ADN”,所以有需要解析 ADN 的数据。
            这个函数可以访问SIM的全部联系人,这里只显示最近新建的联系人的相关信息,如果要显示全部,代码需要修改一下,在Copy函数下增加相应代码就可以获取所以联系人的信息。具体实现如下:
    void CAknExEditorContainer::ReadSIML()
            {
            //定义名片,存放电话薄姓名和电话
                    struct AspContactList
                    {
                    TBuf<30> iName;
                    TBuf<30> iTel;
                    };
                    AspContactList aRecords;
                    RBuf16 buf16;//存储数据
                    _LIT(str,"\f");//换行
            //建立RTelServer会话
                    RTelServer telServer;
                    User::LeaveIfError(telServer.Connect());
                    CleanupClosePushL(telServer);
                    TRequestStatus status;
                    RTelServer::TPhoneInfo info;
                    telServer.GetPhoneInfo(0, info);
                    RMobilePhone phone;
                    User::LeaveIfError(phone.Open(telServer, info.iName));
                    CleanupClosePushL(phone);
                    RMobilePhoneBookStore bookStore;
            //ETel的 sub-session 的名字从 "S1" 到 "S29"
            //sim卡上的通信录格式是 "ADN", 下面3个名字包含 ADN
            //_LIT(KETelMeAdnPhoneBook,"S1");
            //_LIT(KETelTaAdnPhoneBook,"S6");
            //_LIT(KETelIccAdnPhoneBook,"S7");
            const TInt storenum[] = { 1, 6, 7, };
            TUint j = 0;
            for ( ; j < sizeof(storenum) / sizeof(storenum[0]); j++ )
                    {
                            TBuf<10> storename;
                            storename.Copy(_L("S"));
                            storename.AppendNum(storenum[j]);
                            TInt err = bookStore.Open(phone, storename);
                            if ( err != KErrNone )
                                    { //open failed, try next
                                            continue;
                                    }
                            CleanupClosePushL(bookStore);
                            RMobilePhoneBookStore::TMobilePhoneBookInfoV1 storeInfo;
                            RMobilePhoneBookStore::TMobilePhoneBookInfoV1Pckg storeInfoPckg(storeInfo);
                            bookStore.GetInfo(status, storeInfoPckg);
                            User::WaitForRequest(status);
                            if ( status.Int() != KErrNone )
                                    {
                                            CleanupStack::PopAndDestroy();
                                            continue;
                                    }
                            TInt alen=storeInfo.iUsedEntries*70;
                            if ( storeInfo.iUsedEntries < 1 )
                                    { //not record
                                            CleanupStack::PopAndDestroy();
                                            continue;
                                    }
                            HBufC8* hbuf = HBufC8::NewLC(storeInfo.iTotalEntries * 100);
                            TPtr8 recordbuf = hbuf->Des();
                            // Read the own number entry
                            status = KRequestPending;
                            bookStore.Read(status, 1, storeInfo.iTotalEntries, recordbuf);
                            User::WaitForRequest(status);
                            if ( status.Int() != KErrNone )
                                    {
                                            CleanupStack::PopAndDestroy(hbuf);
                                            continue;
                                    }
                            AspContactList record;
                            TInt pos = 0; //pos
                            TInt len = recordbuf.Length();
                            buf16.Create(alen);
                            while ( pos < len )
                                    {
                                            if ( recordbuf[pos] == RMobilePhoneBookStore::ETagPBNewEntry && pos != 0 )
                                                    { //new record and not is first ETagPBNewEntry
                                                            if ( record.iName.Length() != 0 || record.iTel.Length() != 0 )
                                                                    {
                                                                            aRecords=record;
                                                                    }
                                                            record.iName.Zero();
                                                            record.iTel.Zero();
                                                    }
                                            //新的栏位前面应该有个0x00
                                            if ( recordbuf[pos++] != 0x00 )
                                                    {
                                                            continue;
                                                    }
                                            if ( pos >= len - 3 )
                                                    { // not have a full tlv
                                                            break;
                                                    }
                                            if ( recordbuf[pos] == RMobilePhoneBookStore::ETagPBText )
                                                    { //name
                                                            pos++;
                                                            TInt namelen = recordbuf[pos] + recordbuf[pos+1] * 256;
                                                            pos += 2; //length has 2 bytes
                                                            if ( (pos + namelen) > len )
                                                                    { //data error
                                                                            break;
                                                                    }
                                                            namelen = Min(namelen, record.iName.MaxLength() * 2);
                                                            record.iName.Copy((const TUint16*)(recordbuf.Ptr() + pos), namelen / 2);
                                                            pos += namelen;
                                                    }
                                            else
                                                    if ( recordbuf[pos] == RMobilePhoneBookStore::ETagPBNumber )
                                                            { //tel number
                                                                    pos++;
                                                                    TInt tellen = recordbuf[pos] + recordbuf[pos+1] * 256;
                                                                    pos += 2;
                                                                    if ( (pos + tellen) > len )
                                                                    { //data error
                                                                            break;
                                                                    }
                                                                    tellen = Min(tellen, record.iTel.MaxLength() * 2);
                                                                    record.iTel.Copy((const TUint16*)(recordbuf.Ptr() + pos), tellen / 2);
                                                                    pos += tellen;
                                                            }
                                    }
                            if ( record.iName.Length() != 0 || record.iTel.Length() != 0 )
                                    { //last record
                                            aRecords=record;
                                    }
            }
                    CleanupStack::PopAndDestroy(2);
                    buf16.Append(aRecords.iName);
                    buf16.Append(str);
                    buf16.Append(aRecords.iTel);
                    ClearTextL();
                    iGTextEd->SetTextL(&buf16);
                    TestSelectedCase(EAknExEditorClearSelection);
            }

    按照这个方法,一步一步终于实现了symbian v3 v5的sim卡联系人的读取,心情特别舒畅,于是转发这个帖子。

    感谢devdiv的Hency,感谢devdiv与csdn论坛提供大量资料,感谢谷歌百度提供搜索。

  • 相关阅读:
    《汇编语言》(王爽)课后答案
    宝石迷阵-2019头条笔试题
    变量名拆分 -头条2019笔试题
    幸存者游戏, 数字对生成树, 飞机最低可俯冲高度,整理书架 -paypal笔试题2019
    括号序列, 避嫌抢劫-拼多多笔试题
    趣味字母卡片-拼多多笔试题
    爱健身的小王, 修改矩阵,最长上升子串 -美团2019笔试题
    机器人跳跃问题和毕业旅行-头条2019笔试题
    特征提取-头条2019笔试题
    疏散人群-京东2019笔试题
  • 原文地址:https://www.cnblogs.com/yaoliang11/p/2020740.html
Copyright © 2011-2022 走看看