Java Reference
In-Depth Information
private void addContact( ContactList list, String firstName, String lastName,
String street, String city, String country, String postalcode)
throws PIMException {
Contact ct = list.createContact();
String [] name = new String[contList.stringArraySize(Contact.NAME)];
name[Contact.NAME_GIVEN] = firstName;
name[Contact.NAME_FAMILY] = lastName;
ct.addStringArray(Contact.NAME,Contact.ATTR_NONE , name);
String [] addr = new String[contList.stringArraySize(Contact.ADDR)];
addr[Contact.ADDR_STREET] = street;
addr[Contact.ADDR_LOCALITY] = city;
addr[Contact.ADDR_COUNTRY] = country;
addr[Contact.ADDR_POSTALCODE] = street;
ct.addStringArray(Contact.ADDR, Contact.ATTR_NONE , addr);
ct.commit();
}
}
Note the use of the verifyPIMSupport() method to check for PIM Optional Package before
proceeding. The addContact() method is used to add a contact to the PIM list. Only the NAME
and ADDR fields are set in this example.
Build and run this on the emulator before proceeding with the next MIDlet. This will seed
the PIM database with the contact records.
The PIM MIDlet in Listing 9-4 reads the contact list using the PIM optional API and shows
the names of all the contacts in the database.
Listing 9-4. A MIDlet to Display Contact Names in the PIM Database
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.pim.*;
import java.io.*;
import java.util.*;
import javax.microedition.lcdui.List;
public class PIMMIDlet
extends MIDlet
implements CommandListener {
private ContactList contList = null;
private Enumeration contacts = null;
Search WWH ::




Custom Search