Import a contact

You can import contact information from a compatible input stream to a contact list on a BlackBerry® device. You can import contact information by invoking fromSerialFormat(InputStream, String), and passing in as arguments the InputStream from which the PIMItem is written and the character encoding format to use. Supported character encoding formats include UTF8, ISO-8859-1, and UTF-16BE.
  1. Import the required classes and interfaces.
    import java.io.ByteArrayOutputStream;
    import javax.microedition.pim.Contact;
    import javax.microedition.pim.ContactList;
    import javax.microedition.pim.PIM;
    import javax.microedition.pim.PIMItem;
  2. Invoke PIM.getInstance().fromSerialFormat() to return an array of PIM items.
    ByteArrayInputStream istream = 
       new ByteArrayInputStream(outputStream.toByteArray());
    PIMItem[] pi = PIM.getInstance().fromSerialFormat(istream, "UTF8");
  3. Open a contact list and invoke ContactList.importContact() to create a new contact by using a PIM item.
    ContactList contactList = (ContactList) 
       PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
    Contact contact2 = contactList.importContact((Contact) pi[0]);
    contact2.commit();
Next topic: Delete a contact
Previous topic: Export a contact

Was this information helpful? Send us your comments.