在我的应用程序中,我需要将我的应用程序中的联系信息添加到 BlackBerry 的电话簿中。我怎样才能实现它?
我参考了 Java 开发指南“创建联系人并将其分配给联系人列表”
在我的应用程序中,我需要将我的应用程序中的联系信息添加到 BlackBerry 的电话簿中。我怎样才能实现它?
我参考了 Java 开发指南“创建联系人并将其分配给联系人列表”
创建一个联系人,每次您必须检查它是否支持该字段
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 ) {
}
查看联系文档以获取更多信息