×
Namespaces

Variants
Actions

Create a contact group using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search

This code snippet shows how to create a group in the Symbian contact database. 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.

Article Metadata
Platform Security
Capabilities: WriteUserData
Article
Created: mayankkedia (12 May 2009)
Last edited: hamishwillee (10 Feb 2012)

Source

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;
}


Links

This page was last modified on 10 February 2012, at 06:24.
51 page views in the last 30 days.
×