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
Developer
editormax
Posts: 133
Registered: ‎07-20-2009
My Device: Not Specified

How to restore all contact list

    try{
      
      FileConnection fconn = (FileConnection) Connector.open("file:///" + directory + name + ".csv");

      InputStream is = fconn.openInputStream();

      PIMItem[] items = PIM.getInstance().fromSerialFormat(is, "UTF8");
      
      for(int i = 0 ; i < items.length ;i++){
        ContactList contactList = (ContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.WRITE_ONLY);
        Contact newContact = contactList.importContact((Contact) items[i]); 
        newContact.commit();
      }
    System.out.println("Number i " + items.length);
      is.close();
      fconn.close();
    }
    catch (Exception e){
      e.printStackTrace();
    }
  }
 
 
i want to use this coding to restore all my backup contacts, but i just can restore the first one, anyone can help.....thanks you
Please use plain text.
Developer
misty83
Posts: 745
Registered: ‎01-04-2009
My Device: 8300, 8800, 8700f, 9000

Re: How to restore all contact list

try this:

 

public void readItems(){ try{ _contactList = (ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY); _enum = _contactList.items(); while(_enum.hasMoreElements()){ _contact = (Contact)_enum.nextElement(); _name = _contact.getStringArray(Contact.NAME, 0); _firstName = _name[Contact.NAME_GIVEN]; _lastName = _name[Contact.NAME_FAMILY]; System.out.println.(""+_firstName+" "+_lastName, "", 0); } }catch(Exception e){ } }//end of readItems

 

 

regards

Please use plain text.
Developer
editormax
Posts: 133
Registered: ‎07-20-2009
My Device: Not Specified

Re: How to restore all contact list

thanks you for reply....But i think maybe i say not clear enough. I aready have a contacts csv which is write by toSerialFormat. now i want to restore it to device's contact book. but i only can get the first one 
Please use plain text.
Developer
cream8tor
Posts: 30
Registered: ‎05-07-2009
My Device: Not Specified

Re: How to restore all contact list

Even though PIM.fromSerialFormat() returns an array of PIMItem objects, it only actually parses 1 item from the input stream.  So try repeatedly invoking fromSerialFormat(), once for each PIMItem to read.  Basically, put your entire code block into a while(true) loop and see if that works.

 

Note the @return javadoc comments for fromSerialFormat() that read that it returns

 

an array of newly created PIM items created from the InputStream. In some cases, more than one PIM item may be created from a complete entry (for example, a single vCalendar entry may produce two PIM items, both an Event and a ToDo).

 

Please use plain text.
Contributor
sanshah90
Posts: 36
Registered: ‎06-28-2012
My Device: BB10
My Carrier: RIM

Re: How to restore all contact list

Hi,

 

I am getting same kind of error.

I tried the solution cream8tor has provided but it is not working.

 

Can you please provide some working solution or sample demo or some other way by which I can solve this problem.

 

Thanks

Please use plain text.