×
Namespaces

Variants
Actions

Fetch Image from contacts

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: Kavit Patel (04 Oct 2008)
Last edited: hamishwillee (30 May 2013)

The following code snippet shows how to fetch the image stored in contacts.


Code

 
CContactDatabase* contactsDb = CContactDatabase::OpenL();
CleanupStack::PushL(contactsDb);
 
contactsDb->SetDbViewContactType(KUidContactCard);
 
//create iterator for contactsDb
TContactIter contactIterator(*contactsDb);
TContactItemId contactId;
 
//go through contacts while there any info
while( ( contactId = contactIterator.NextL() ) != KNullContactId )
{
CContactItem* contactItem = contactsDb->ReadContactL(contactId);
CleanupStack::PushL(contactItem);
 
CContactItemFieldSet& fieldSet = contactItem->CardFields();
HBufC8* image;
 
TInt index = fieldSet.Find(KUidContactFieldVCardMapPHOTO);
if (index != KErrNotFound)
{
CContactItemField& field = fieldSet[index];
image = field.StoreStorage()->Thing();
//Here image data contains the photo for the buddy.
}
 
contactsDb->CloseContactL(contactItem->Id());
CleanupStack::PopAndDestroy(); //contactItem
}
 
CleanupStack::PopAndDestroy(); //contactsDb

In above code the "image" buffer stores the phone book contact photo. We can store them in a file to make an icon for the same.

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