×
Namespaces

Variants
Actions

Find a contact group

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


The following example shows how to find a contact group progrmatically. This kind of behavior might be needed in case you want to check before creating contact groups.

Header file required:

#include <cntdb.h>

CContactDatabase link against library cntmodel.lib so add following line to your .mmp file.

LIBRARY cntmodel.lib

Add following lines in .cpp file.

CContactDatabase* contactDbHandle;
TInt err;
TRAP(err, contactDbHandle= CContactDatabase::OpenL(););
if(err != KErrNone)
{
// Something went wrong lets bail out
return;
}
 
CContactIdArray* idArray = contactDbHandle->GetGroupIdListL();
CleanupStack::PushL(idArray);
TInt count = idArray->Count();
 
TInt groupId;
for(TInt i=0; i<count && iGroupExists == EFalse; i++)
{
CContactGroup* contact = static_cast<CContactGroup*>(contactDbHandle->OpenContactL( (*idArray) [i]));
CleanupStack::PushL( contact );// cleanup stack contains (contact,idArray)
TBuf<255> groupName = contact->GetGroupLabelL();
if(groupName.Compare(/*The group label you wana search*/) == 0)//group exists
{
groupId= contact->Id(); // this is the group id for the searched group
}
else
{
// Group does not exist, follow the link below to create the group
}
contactDbHandle->CloseContactL( (*idArray)[i]);
CleanupStack::PopAndDestroy(contact);// cleanup stack contains (idArray)
}
CleanupStack::PopAndDestroy(idArray);
CAPABILITY ReadUserData

Added by - Mayank on 12/05/2009

Links

Create a contact group

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