×
Namespaces

Variants
Actions
Revision as of 09:33, 26 July 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Import a vCard containing photo data returns PIM exception on Series 40 5th & 6th Edition devices

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Compatibility
Device(s): all Series 40 5th & 6th Edition devices
Article
Created: Grandlu (30 Aug 2010)
Last edited: hamishwillee (26 Jul 2013)

Contents

Overview

Importing a vCard which contains photo data returns PIM exception during commit on every Series 40 5th Edition & Series 40 6th Edition devices

Description

If you try to import a vCard into PIM on any device of 5th or 6th Edition using the fromSerialFormat() method, and if this vCard contains PHOTO data / field, then when calling the commit method on the imported contact a PIMException get raised: javax.microedition.pim.PIMException: Error writing to contact DB, error=0x80000022retryCount = 0

How to reproduce

try {
 
file = (FileConnection) Connector.open(fileName, Connector.READ_WRITE);
// If there is no file exit
if (file.exists() == false) {
throw new Exception("File for import not found.");
}
inStream = file.openInputStream();
 
PIMItem[] items = pim.fromSerialFormat(inStream, "UTF-8");
// Assume there is only one contact item in file.
if (items.length > 0) {
Contact ct = (Contact) (items[0]);
myContact = contactList.importContact(ct);
myContact.commit();
}
} catch (PIMException pimex) {
// Exception returned when hit commit with Series 40 5th Edition & Series 40 6th Edition
}

Run code above or similar where "fileName" is the path + filename of a vCard file containing the PHOTO field and associated data.

Solution

Workaround:

When the exception has been caught, if you just extract the PHOTO data from the contact to save them, then remove them from the contact and add them again right away, then the commit won't raise an exception:

try {
 
file = (FileConnection) Connector.open(fileName, Connector.READ_WRITE);
// If there is no file exit
if (file.exists() == false) {
throw new Exception("File for import not found.");
}
inStream = file.openInputStream();
 
PIMItem[] items = pim.fromSerialFormat(inStream, "UTF-8");
// Assume there is only one contact item in file.
if (items.length > 0) {
Contact ct = (Contact) (items[0]);
myContact = contactList.importContact(ct);
myContact.commit();
}
} catch (PIMException pimex) {
// Exception returned when hit commit with Series 40 5th Edition & Series 40 6th Edition
try {
if (contactList.isSupportedField(Contact.PHOTO)) {
// Extract the PHOTO data
byte[] photo = contact.getBinary(Contact.PHOTO, 0);
// Remove PHOTO data from contact
contact.removeValue(Contact.PHOTO, 0);
// Add the same PHOTO data to contact
contact.addBinary(Contact.PHOTO, Contact.ATTR_NONE, photo, 0, photo.length);
// Commit again
contact.commit();
}
} catch (Exception e) {
// Exception handling
}
}
This page was last modified on 26 July 2013, at 09:33.
58 page views in the last 30 days.
×