如何使用BlackBerry API通过联系人姓名获取联系电话 [英] How to get Contact numbers by contact name using blackberry api

查看:83
本文介绍了如何使用BlackBerry API通过联系人姓名获取联系电话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按联系人名称搜索时如何得到所有联系人号码的联系人。
鉴于联系人姓名,我们如何能搜索地址簿,并得到所有与联系人相关联的联络号码。

How to get all contact numbers for a Contact when searching by contact 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

//这里是code段迭代联系人的所有电话NRS
如果((contList.isSupportedField(BlackBerryContact.TEL))及及(c.countValues​​(BlackBerryContact.TEL)> 0)){
                    numValues​​ = 0;
                    尝试{
                        numValues​​ = c.countValues​​(BlackBerryContact.TEL);
                    }赶上(例外localException){
                    }
                    的for(int i = 0; I< numValues​​ ++我){
                        如果(c.getAttributes(BlackBerryContact.TEL,I)== BlackBerryContact.ATTR_WORK)
                            worknumber = c.getString(BlackBerryContact.TEL,I);
                        否则,如果(c.getAttributes(BlackBerryContact.TEL,I)== BlackBerryContact.ATTR_HOME)
                            homenumber = c.getString(BlackBerryContact.TEL,I);
                        否则,如果(c.getAttributes(BlackBerryContact.TEL,I)== BlackBerryContact.ATTR_MOBILE)
                            移动电话号码= c.getString(BlackBerryContact.TEL,I);
                        否则,如果(c.getAttributes(BlackBerryContact.TEL,I)== BlackBerryContact.ATTR_OTHER)
                            othernumber = c.getString(115,I);
                        否则,如果(c.getAttributes(BlackBerryContact.TEL,I)== BlackBerryContact.ATTR_PAGER)
                            pagernumber = c.getString(BlackBerryContact.TEL,I);
                        否则,如果(c.getAttributes(BlackBerryContact.TEL,I)== BlackBerryContact.ATTR_FAX){
                            faxnumber = c.getString(BlackBerryContact.TEL,I);
                        }
                    }

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

}

这篇关于如何使用BlackBerry API通过联系人姓名获取联系电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆