Sunday, August 10, 2008

A Simple example of PIM in J2ME application [Source Code]

import java.util.Enumeration;
import javax.microedition.pim.*;

public class PIMRunner extends Thread {
private PIMTest midlet;

public PIMRunner(PIMTest midlet) {
this.midlet = midlet;
}

public void run() {
try {
ContactList addressbook = (ContactList) (PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY));
Contact contact = null;
Enumeration items = addressbook.items();
while (items.hasMoreElements()) {
contact = (Contact) (items.nextElement());
String nm[] = contact.getStringArray(Contact.NAME, 0);
if (nm[0] != null)
midlet.addMsg("Name:" + nm[0]);
else
midlet.addMsg("Name:" + nm[1]);

int count = contact.countValues(Contact.TEL);
for (int i = 0; i < count; i++) {
String tnum = contact.getString(Contact.TEL, i);
midlet.addMsg("Telephone:" + tnum );
}
midlet.addMsg("\n");
}
} catch (Exception e) {
midlet.addMsg(e.getMessage());
e.printStackTrace();
}
}

}

No comments:

search engine

Custom Search