开发者

How to get Contact numbers by contact name using blackberry api

How to get all contact numbers for a Contact when searching by 开发者_如何学JAVAcontact name. Given a contact name how can we search the address book and get all the contact numbers associated with the contact.


get the contact list and search for your contact name between the contacts


    BlackBerryContactList contList = (BlackBerryContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST,PIM.READ_ONLY);
            Enumeration er = contList.items();
            while (er.hasMoreElements())
            {
                BlackBerryContact c = (BlackBerryContact)er.nextElement();
if ((contList.isSupportedField(BlackBerryContact.NAME)) && (c.countValues(BlackBerryContact.NAME) > 0))
                {
                    String[] name = c.getStringArray(BlackBerryContact.NAME, 0);
                    String firstName = name[BlackBerryContact.NAME_GIVEN];
                    String lastName = name[BlackBerryContact.NAME_FAMILY];
                    fullname = "";
                    if (firstName != null)
                    {
                        fullname += firstName + " ";
                    }

//check if the name is the name you want

//here is the code snippet to iterate all phone nrs of a contact if ((contList.isSupportedField(BlackBerryContact.TEL)) && (c.countValues(BlackBerryContact.TEL) > 0)) { numValues = 0; try { numValues = c.countValues(BlackBerryContact.TEL); } catch (Exception localException) { } for (int i = 0; i < numValues; ++i) { if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_WORK) worknumber = c.getString(BlackBerryContact.TEL, i); else if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_HOME) homenumber = c.getString(BlackBerryContact.TEL, i); else if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_MOBILE) mobilenumber = c.getString(BlackBerryContact.TEL, i); else if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_OTHER) othernumber = c.getString(115, i); else if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_PAGER) pagernumber = c.getString(BlackBerryContact.TEL, i); else if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_FAX) { faxnumber = c.getString(BlackBerryContact.TEL, i); } }

                System.out.println("---<><><>Mobile Phone Nr: " + mobilenumber);
                System.out.println("---<><><>Work Phone Nr: " + worknumber);
                System.out.println("---<><><>Home Phone Nr: " + homenumber);
                System.out.println("---<><><>Pager Nr: " + pagernumber);
                System.out.println("---<><><>Fax Nr: " + faxnumber);
                System.out.println("---<><><>Other Nr: " + othernumber);
            }

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜