The following example shows how to create a group in the contact DB. The created group shows up in the contact groups on the contact application of the device. This kind of behavior might be needed in case you want to create the group progrmatically and do something with it.
Header file required:
#include <cntdb.h>
CContactDatabase link against library cntmodel.lib so add following line to your .mmp file:
LIBRARY cntmodel.lib
Capabilities:
CAPABILITY WriteUserData
Add following lines in .cpp file.
TInt CreateContactGroupL(const TDesC& aGroupName)
{
TInt err = KErrNone;
CContactDatabase* contactDbHandle;
TRAP(err, contactDbHandle = CContactDatabase::OpenL());
if(err == KErrNone)
{
CContactGroup* contact = static_cast<CContactGroup*>(contactDbHandle->CreateContactGroupL(aGroupName, 0));
CleanupStack::PushL(contact);
TInt groupId = contact->Id(); // this is the group id for your group
contactDbHandle->CloseContactL(groupId); //Make sure to close the contact else no one will be able to use the created group till then..
CleanupStack::PopAndDestroy(contact);
}
return err;
}
No related wiki articles found