Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Getting Contact Database Change Event using Symbian C++

From Wiki
Jump to: navigation, search

This article shows how to register for notification of Symbian contact database change events. To receive events we inherit from MContactDbObserver and implement the virtual function HandleDatabaseEventL() (this function is called when a contact database event occurs).

Article Metadata
Created: vasant21 (07 May 2007)
Last edited: hamishwillee (25 Jan 2012)

If you are not familiar with Observer Pattern, see Observer

Header required:

#include <CNTDBOBS.H> //MContactDbObserver
#include <cntdb.h> // CContactDatabase, CContactChangeNotifier

Library needed:

LIBRARY  cntmodel.lib // CContactDatabase, CContactChangeNotifier

Source code:

class CContactDatabaseObserver : public CBase, MContactDbObserver
// we need to override the virtual function from the base class //
virtual void HandleDatabaseEventL( TContactDbObserverEvent aEvent );
// Handle contact database events //
void CContactDatabaseObserver::HandleDatabaseEventL(TContactDbObserverEvent aEvent)
//if any contact deleted in phonebook
case EContactDbObserverEventContactDeleted:
//event if any contact changed
case EContactDbObserverEventContactChanged:
//event if any new contact added to phonebook
case EContactDbObserverEventContactAdded:
//check TContactDbObserverEventType for more events.
//We must also create the CContactChangeNotifier object to register itself to receive events.
CContactDatabase* ContactDatabase = CContactDatabase::OpenL();
// Here iContactDatabaseObserver is a CContactDatabaseObserver pointer //
CContactChangeNotifier* DatabaseNotifier =
CContactChangeNotifier::NewL(*ContactDatabase , this);// Changes by aamitgupta on date 5/06/2008

Related Links:

This page was last modified on 25 January 2012, at 00:17.
34 page views in the last 30 days.