将联系信息放入Blackberry的电话簿中

时间:2012-05-01 04:46:37

标签: blackberry contact addressbook

在我的应用程序中,我需要将我的应用程序中的联系信息添加到BlackBerry的电话簿中。 我怎样才能实现它?

我已经参考了Java开发指南"Create a contact and assign it to a contact list"

2 个答案:

答案 0 :(得分:0)

创建联系人,每次必须检查它是否支持字段

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 ) {
 }

答案 1 :(得分:0)

查看Contact documentation了解更多信息