0

In my application I need to add contact info from my app into phonebook of BlackBerry. How can I achieve it?

I have referred to the Java development guide "Create a contact and assign it to a contact list"

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Yatin
  • 2,969
  • 9
  • 34
  • 68

2 Answers2

0

Create a contact and everytime you have to check out that if it supports the Field

ContactList contacts = null;
 try {
     contacts = (ContactList) PIM.getInstance().openPIMList( PIM.CONTACT_LIST,
             PIM.READ_WRITE );
 } catch( PIMException e ) {
     // An error occurred
     return;
 }
 Contact contact = contacts.createContact();

 String[] name = new String[ contacts.stringArraySize( Contact.NAME ) ];
 name[ Contact.NAME_GIVEN ] = "John";
 name[ Contact.NAME_FAMILY ] = "Public";

 String[] addr = new String[ contacts.stringArraySize( Contact.ADDR ) ];
 addr[ Contact.ADDR_COUNTRY ] = "USA";
 addr[ Contact.ADDR_LOCALITY ] = "Coolsville";
 addr[ Contact.ADDR_POSTALCODE ] = "91921-1234";
 addr[ Contact.ADDR_STREET ] = "123 Main Street";

 try {
     contact.addString( Contact.NAME_FORMATTED, PIMItem.ATTR_NONE,
             "Mr. John Q. Public, Esq." );
     contact.addStringArray( Contact.NAME, PIMItem.ATTR_NONE, name );
     contact.addStringArray( Contact.ADDR, Contact.ATTR_HOME, addr );
     contact.addString( Contact.TEL, Contact.ATTR_HOME, "613-123-4567" );
     contact.addToCategory( "Friends" );
     contact.addDate( Contact.BIRTHDAY, PIMItem.ATTR_NONE, new Date().getTime() );
     contact.addString( Contact.EMAIL, Contact.ATTR_HOME
             | Contact.ATTR_PREFERRED, "jqpublic@xyz.dom1.com" );

 } catch( UnsupportedFieldException e ) {
     // In this case, we choose not to save the contact at all if any of the
     // fields are not supported on this platform.
     System.out.println( "Contact not saved" );
     return;
 }

 try {
     contact.commit();
 } catch( PIMException e ) {
     // An error occured
 }
 try {
     contacts.close();
 } catch( PIMException e ) {
 }
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Yatin
  • 2,969
  • 9
  • 34
  • 68
0

Check out the Contact documentation for more information

Michael Donohue
  • 11,776
  • 5
  • 31
  • 44
Yatin
  • 2,969
  • 9
  • 34
  • 68