PIM Contact : PIM « J2ME « Java Tutorial






import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.midlet.MIDlet;
import javax.microedition.pim.Contact;
import javax.microedition.pim.ContactList;
import javax.microedition.pim.PIM;

public class SeedMIDlet extends MIDlet implements CommandListener {

  private Form mForm = new Form("Data Seeded");

  private Command mExitCommand;

  public SeedMIDlet() {
    try {
      PIM pimInst = PIM.getInstance();
      contList = (ContactList) pimInst.openPIMList(PIM.CONTACT_LIST,
          PIM.READ_WRITE);
      Contact ct = contList.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();

      if (contList != null)
        contList.close();
      contList = null;

    } catch (Exception ex) {

      return;
    }
    mForm.append(new StringItem(null, "PIM data stored."));
    mExitCommand = new Command("Exit", Command.EXIT, 0);

    mForm.addCommand(mExitCommand);
    mForm.setCommandListener(this);
  }

  public void startApp() {
    Display.getDisplay(this).setCurrent(mForm);
  }

  public void pauseApp() {
  }

  public void destroyApp(boolean flg) {
  }

  public void commandAction(Command c, Displayable s) {
    if (c == mExitCommand) {
      destroyApp(true);
      notifyDestroyed();
    }
  }
  private ContactList contList = null;
}








31.46.PIM
31.46.1.PIM Install Tester
31.46.2.PIM DemoPIM Demo
31.46.3.PIM Contact