Java Reference
In-Depth Information
The individual fields of a contact are addressed by field IDs. The
field IDs
are integer values which are
defined in the Contact interface. Examples for fields IDs are
Contact.FORMATTED_NAME
or
Contact.PUBLIC_KEY
.
String-Based Data
String data is added to a
Contact
using the
setString()
method, which takes two parameters.
The first parameter is the field ID, and the second takes the string to be stored. For reading string data
fields, the method
getString()
is provided. This method takes the field ID to be read as a
parameter and returns the corresponding value. If the field has not been set,
null
is returned.
A contact containing one field, the formatted name, is created as follows:
ContactList myContacts = PIM.openContactList (PIM.READ_WRITE);
Contact myContact = myContacts.createContact();
myContact.setString(Contact.FORMATTED_NAME, "John, Smith");
Please note that a try-catch block for the
PIMException
is missing in the code above. We will omit
the mandatory try-catch block from all following code snippets.
A special field is the UID field. It contains an identifier that is unique for each contact. The unique
identifier is generated automatically and cannot be modified. It can be used to quickly retrieve a
particular contact.
Table 7.1. Field ID Constants for String-based Data Defined in the Contact Interface
Field Name
Description
ORG
The organization name
FORMATTED_NAME
The formatted name
NAME_FAMILY
The family name
NAME_GIVEN
The given name
NAME_OTHER
Undefined information
NAME_PREFIX
The name prefix
NAME_SUFFIX
The name suffix
NICKNAME
A nickname
NOTE
A note
PUBLIC_KEY
The public key, such as a PGP public key
TITLE
The title
UID
The contact's UID
URL
A URL associated with the contact
Date-Based Data
In addition to text fields, the PIM API supports fields for storing dates, such as a person's birthday.
Similar to the
setString()
and
getString()
methods, the
Contact
class supports the
setDate()
and
getDate()
methods to store and retrieve dates in a
Contact
. The set method
takes a field ID such as
BIRTHDAY
and a given
Date
object as parameters. The date can be retrieved
by giving the corresponding field ID to the
getDate()
method.
Another field containing a date is
REVISION
. This entry stores the date when the contact was last
modified. Setting this value is not recommended because it is automatically done by the
implementation.
BIRTHDAY
and
REVISION
are the only date fields supported by PDAP.
Search WWH ::
Custom Search