Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
gauravpalvia
Posts: 18
Registered: ‎01-04-2009
My Device: Not Specified

Importing Exporting contacts using vCard

Does BB provide any API to import and export contacts into existing contact list from and to vCard.

BlackBerry Development Advisor
MSohm
Posts: 14,757
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Importing Exporting contacts using vCard

Yes, refer to the PIM.fromSerialFormat(InputStream is, String enc) and PIM.toSerialFormat(PIMItem item, OutputStream os, String enc, String dataFormat) methods.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Member
digrigolid
Posts: 1
Registered: ‎06-13-2011
My Device: 8520

Re: Importing Exporting contacts using vCard

Could anyone explain me in simple words how to do it?

New Contributor
nsantini
Posts: 4
Registered: ‎08-29-2011
My Device: BlackBerry Torch 9800

Re: Importing Exporting contacts using vCard

This is what I do:

 

export

 

BlackBerryContactList contactList = (BlackBerryContactList)PIM.getInstance().openPIMList(

PIM.CONTACT_LIST, PIM.READ_WRITE);

String[] dataFormats = PIM.getInstance().supportedSerialFormats(PIM.CONTACT_LIST);
Enumeration enu = contactList.items();
while (enu.hasMoreElements()) {

Contact c = (Contact)enu.nextElement();

ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
PIM.getInstance().toSerialFormat(c, byteStream, null, dataFormats[0]);
String contact = byteStream.toString();

}

 

 

import

 

ByteArrayInputStream is = new ByteArrayInputStream(contactStr.getBytes());
PIMItem[] pi = PIM.getInstance().fromSerialFormat(is, null);

ContactList contactList = (ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
Contact contact2 = contactList.importContact((Contact)pi[0]);
Enumeration matching = contactList.items(contact2);
if(matching.hasMoreElements()) {
System.out.println("found the first contact");
} else {
System.out.println("adding the first contact");
contact2.commit();
}

New Member
Hisham_salah
Posts: 1
Registered: ‎01-26-2012
My Device: BlackBerry Curve 3G 9300

Re: Importing Exporting contacts using vCard

3reftakshi ana kida 

 

Simple english please:smileyfrustrated: