Java Reference
In-Depth Information
Adding Attributes to Field Values
Attributes are bit flags used to qualify field values. Attributes defined in the Contact interface
include ATTR_FAX , ATTR_HOME , ATTR_MOBILE , ATTR_OTHER , ATTR_PAGER , ATTR_SMS , ATTR_WORK ,
ATTR_AUTO , ATTR_ASST , and ATTR_PREFERRED . Attributes may be combined using the | (bitwise or)
operator.
Attributes are useful for some fields that can have multiple values. For example, the
Contact.TEL field may have a value of “402-323-1111” with ATTR_FAX , another value of
“402-341-8888” with ATTR_WORK , and a value of “402-872-2001” with ATTR_HOME | ATTR_PREFERED .
Only one value can be marked with ATTR_PREFERRED . The index corresponding to the
preferred attribute, if set, can be obtained using this method on the Contact interface:
public int getPreferredIndex(int field)
Attributes are specified when adding values to a field. A series of data type-dependent
methods on Contact (actually PIMItem ) are available for this purpose:
public void addBinary(int field, int attributes, byte[] value,
int offset, int length)
public void addDate(int field, int attributes, long value)
public void addInt(int field, int attributes, int value)
public void addString(int field, int attributes, String value)
public void addBoolean(int field, int attributes, boolean value)
public void addStringArray(int field, int attributes, String [] value)
Most fields are single valued, and not all fields have attributes. You can use
Contact.ATTR_NONE for an attribute when adding a value to a field.
Creating a New Contact
Creating a new Contact is a three-step process (for Event or ToDo , the procedure is similar):
1.
Call the factory method, createContact() , on the ContactList , returning a new Contact
for the list.
2.
Use the add<data type>() methods of the Contact to set values for the fields of
the Contact .
Call the commit() method on the Contact to save the new field values to persistent storage.
3.
The createContact() method on the ContactList will create a new Contact item for the list,
with no value set for any of the fields:
public Contact createContact()
The commit() method of Contact causes the underlying implementation to save all the new
field values to persistent storage.
public void commit() throws PIMException
For example, the code to create a new Contact with only a Contact.NAME field may be
as follows:
Search WWH ::




Custom Search