×
Namespaces

Variants
Actions

Delete a Contact Item

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: mayankkedia (06 May 2009)
Last edited: hamishwillee (30 May 2013)
Reviewer Approved    Thumbs up icon sm.jpg


The following example shows how to select a contact from the native contact database and delete it. This kind of behavior might be needed whenever you want to do something with the contact per se, without using the contacts application's delete option.

Header file required:

#include <CPbkContactEngine.h>
#include <CPbkSingleEntryFetchDlg.h>
#include <rpbkviewresourcefile.h>

CPbkSingleEntryFetchDlg & RPbkViewResourceFile link against library PbkView.lib , while CPbkContactEngine links against pbkeng.lib so add following line to your .mmp file.

LIBRARY PbkView.lib pbkeng.lib

Add following lines in .cpp file.

// load the contacts dialog resources
CCoeEnv* env = CEikonEnv::Static();
 
//Phonebook Engine for Phonebook Views
CPbkContactEngine* pbkContactEng = CPbkContactEngine::NewL( &env->FsSession());
CleanupStack::PushL(pbkContactEng);
 
RPbkViewResourceFile pbkRes(*env);
pbkRes.OpenL();
 
//Parameters for a Single Entry Dialog
CPbkSingleEntryFetchDlg::TParams params;
params.iPbkEngine = pbkContactEng;
params.iSelectedEntry = -1;
 
// Create and display a Single Entry Dialog
// params.iSelectedEntry will hold the selected Contact Id
CPbkSingleEntryFetchDlg* entryFetchDlg = CPbkSingleEntryFetchDlg::NewL(params);
entryFetchDlg->ExecuteLD(); //entryFetchDlg destroyed here
TContactItemId contactId = params.iSelectedEntry;
 
if(contactId != -1)
{
pbkContactEng->DeleteContactL(contactId); // if user selected a contact lets delete
}
 
pbkRes.Close();
CleanupStack::PopAndDestroy(); //pbkContactEng
CAPABILITY ReadDeviceData ReadUserData WriteDeviceData WriteUserData

Added by - Mayank on 06/05/2009

This page was last modified on 30 May 2013, at 07:33.
33 page views in the last 30 days.