如何使用blackberry api通过联系人姓名获取联系号码

时间:2010-03-05 10:22:06

标签: blackberry

按联系人姓名搜索时,如何获取联系人的所有联系号码。 给定联系人姓名,我们如何搜索地址簿并获取与联系人相关联的所有联系号码。

1 个答案:

答案 0 :(得分:4)

获取联系人列表并在联系人之间搜索您的联系人姓名


    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);
            }

}