Symbian 根据手机号码查电话薄姓名

来源:互联网 发布:安全动画预防网络诈骗 编辑:程序博客网 时间:2024/04/30 16:55
 

TBool CSampleControlAppUi::LookupTelNumber(TDes&aName, const TDesC& aNumber)
    {
   CContactDatabase* contactsDB = CContactDatabase::OpenL();
   CleanupStack::PushL(contactsDB);
   CContactIdArray* iContactIds = NULL;
   CContactItemFieldDef* findFields = newCContactItemFieldDef();
   CleanupStack::PushL(findFields);
   findFields->AppendL(KUidContactFieldPhoneNumber);
    //search thephonenumber field with the keyword;
    iContactIds= contactsDB->FindLC(aNumber, findFields);
    TBool find =EFalse;
    for (TInt i= 0; i < iContactIds->Count();i++)
       {
       CContactItem * p_item =contactsDB->ReadContactL((*iContactIds)[i]);
       CleanupStack::PushL(p_item);
       TInt i_name =p_item->CardFields().Find(KUidContactFieldGivenName);
       TInt i_fname =p_item->CardFields().Find(KUidContactFieldFamilyName);
       TInt i_phone =p_item->CardFields().Find(KUidContactFieldPhoneNumber);
       if (i_name != KErrNotFound || i_fname != KErrNotFound)
           {
           TPtrC16 p_str_name = p_item->CardFields()
           [i_name].TextStorage()->Text();
           TPtrC16 p_str_fname = p_item->CardFields()
           [i_fname].TextStorage()->Text();
           aName.Copy(p_str_fname);
           aName.Append(p_str_name);
           find = ETrue;
           CEikonEnv::Static()->InfoMsg(aName);
           }
       else
           {
           aName.Zero();
           find = EFalse;
           }
       CleanupStack::PopAndDestroy(p_item);
       contactsDB->CloseContactL((*iContactIds)[i]);
       if (find)
           break;
       }
   CleanupStack::PopAndDestroy(3);
    returnfind;

    }

原创粉丝点击