×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    9

    add contact from default phonebook error

    Hi all,

    I am adding contact from default database... and the code is pasted below..
    How to add contacts from phonebook
    From Forum Nokia Wiki
    There are plenty of occasions when you need to add contacts from Phonebook to your Symbian C++ application. Examples are SMS, Call Control applications etc. To do that you have to first load the phonebook's resource file like

    RPbkViewResourceFile phonebookResource( *(CEikonEnv::Static()) );
    phonebookResource.OpenL();In general you would want to allow users to fetch multiple entries from the phonebook dialog so you can use CPbkMultipleEntryFetchDlg and pass the correct parameters. Also attach the correct Phonebook Contact Engine to the dialog. (Here I am picking the default contact book, whereas you may want to display your own special contact book database.) The code may look like

    CPbkMultipleEntryFetchDlg::TParams params;
    CleanupStack::PushL(params);

    CPbkContactEngine* iPbkContactEngine =
    CPbkContactEngine::NewL(&iEikonEnv->FsSession());
    CleanupStack::PushL(iPbkContactEngine);
    params.iContactView = &iPbkContactEngine->AllContactsView();

    CPbkMultipleEntryFetchDlg* fetcher =
    CPbkMultipleEntryFetchDlg::NewL(params, *iPbkContactEngine);
    fetcher->SetMopParent(this);Later just execute the dialog. On return, the dialog will give you a list of contact ids with which you can access individually selected contacts from Contact Engine and process them

    TBuf<30> phoneNumber;

    TInt paramCount = params.iMarkedEntries->Count();
    // Get the selected contacts id array
    for ( TInt i = 0; i < paramCount; ++i )
    {
    const TContactItemId cid = ( *params.iMarkedEntries )[i];
    // Open the selected contact using Phonebook engine,
    // choose correct number (launch list query if needed)
    CPbkContactItem* pbkItem = iPbkContactEngine->ReadContactLC( cid );
    TPbkContactItemField* tmp;
    if ((tmp = pbkItem->FindField(EPbkFieldIdPhoneNumberMobile)) != NULL)
    {
    phoneNumber = tmp->Text();
    if(phoneNumber.Length() > 0){
    if(iData)
    iAppView->AddNumber(phoneNumber);
    }
    }

    CleanupStack::PopAndDestroy(1);//CPbkContactItem
    }In the end clean up your stack and close phonebook resource

    //CPbkContactEngine, CPbkMultipleEntryFetchDlg::TParams
    CleanupStack::PopAndDestroy(2);
    phonebookResource.Close();


    here i am getting error in "AddNumber(phoneNumber)"....
    please tell us what to do......
    please help me...

  2. #2
    Super Contributor
    Join Date
    Mar 2004
    Location
    Bangalore,India
    Posts
    2,146

    Re: add contact from default phonebook error

    Very tough to say, as you have simply copy-pasted everything from the Wiki onto here :-)

    Did you change the iAppView to something from your code, coz once you have the number in 'phoneNumber' I believe the original poster is calling his view function to do the Add Number onto his control or whatever. Idea was to let you know how to access a default contact.

    If you have a specific error after those modifications please feel free to post, also its always nice to let us know what is the error/just mentioning a generic error is very tough to figure out. You can enable error codes using this

    Cheers,
    Mayank

Similar Threads

  1. carbide build problem help please
    By berkcekisbas in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2006-09-26, 19:41
  2. problem with Code Warrior 5.2
    By mayankkedia in forum Symbian
    Replies: 4
    Last Post: 2006-06-22, 08:26
  3. help !! about SIP errors
    By wgarnett in forum Symbian
    Replies: 3
    Last Post: 2006-05-17, 05:30
  4. problem with codewarrior 5.2
    By mayankkedia in forum Symbian Tools & SDKs
    Replies: 3
    Last Post: 2004-09-27, 16:08
  5. Replies: 0
    Last Post: 2002-09-24, 13:11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •