Find a contact group
Article Metadata
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.libAdd 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


(no comments yet)