Categories: PIM | Messaging | Files/Data | Symbian C++ | Code Examples | How To
This page was last modified 08:28, 8 December 2007.
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();
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PhonebookEngine help | alokshriram | General Symbian C++ | 0 | 2005-07-14 20:17 |
| PhoneBook Entried display using J2ME | prayagnarula | Mobile Java Tools & SDKs | 1 | 2006-10-19 23:17 |
| 6270 hardware bug syncing contacts? | phonesync | General Discussion | 1 | 2006-01-25 11:44 |
| 6230 Transfer phonebook to car | rmm20 | PC Suite API and PC Connectivity SDK | 0 | 2004-12-30 22:16 |
| Python script reading contacts blows up Symbian contact DB | RaimondasL | Python | 6 | 2007-04-24 21:36 |
