java me - J2ME fetching sim contacts -
how retrieve both sim , phone book contact using pim in j2me. tried pim.getinstance().listpimlists(pim.contact_list); it's displaying phone book contact.
may method can help you
public static hashlongobject loadcontactfromphone() { pim ipim = pim.getinstance(); string[] allcontactlists = ipim.listpimlists(pim.contact_list); // phone or sim hashlongobject iphonebooklist = new hashlongobject(); int i; (i = 0; < allcontactlists.length; i++) { seek { pimlist ipimlist = ipim.openpimlist(pim.contact_list, pim.read_only, allcontactlists[i]); enumeration ipimlistenum = ipimlist.items(); string icontactname, itelnumber; string []arrname; boolean issupportformettedname = ipimlist.issupportedfield(contact.formatted_name); if(issupportformettedname) { while (ipimlistenum.hasmoreelements()) { seek { contact icontact = (contact) ipimlistenum.nextelement(); icontactname = icontact.getstring(contact.formatted_name, 0); itelnumber = icontact.getstring(contact.tel, 0); } grab (exception e) { logger.logstacktrace(e); continue; } long corephonenumber = stringutils.toccphonenumber(itelnumber); // check duplicate if (iphonebooklist.containskey(corephonenumber)) { continue; } iphonebooklist.put(corephonenumber, icontactname); } } else { while (ipimlistenum.hasmoreelements()) { seek { contact icontact = (contact) ipimlistenum.nextelement(); arrname = icontact.getstringarray(contact.name, contact.attr_none); icontactname = ""; if(arrname[contact.name_family] != null) { icontactname += arrname[contact.name_family]; } if(arrname[contact.name_given] != null) { icontactname += arrname[contact.name_given]; } itelnumber = icontact.getstring(contact.tel, 0); } grab (exception e) { logger.logstacktrace(e); continue; } long corephonenumber = stringutils.toccphonenumber(itelnumber); // check duplicate if (iphonebooklist.containskey(corephonenumber)) { continue; } iphonebooklist.put(corephonenumber, icontactname); } } } grab (pimexception ex) { logger.logstacktrace(ex); } grab (exception otherex) { logger.logstacktrace(otherex); } } homecoming iphonebooklist; }
java-me
No comments:
Post a Comment