Create a contact group using Symbian C++
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.libCapabilities:
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;
}


15 Sep
2009
You could use this code snippet for creating a contact group. It is a useful operation in different cases, for example in your own backup manager, or in your own phonebook application. With the help of the example like this, you could easily manage phone data.