注册。联系人提取

时间:2010-08-05 10:14:58

标签: blackberry contacts

如何检查传入号码是否存在于黑莓联系人列表中..如果存在,我想显示其联系人姓名..

提前致谢..

1 个答案:

答案 0 :(得分:2)

我认为这会对你有所帮助 1.添加电话听众

Phone.addPhoneListener(new AbstractPhoneListener(){
            public void callIncoming(int callId) {
                String number = Phone.getCall(callId).getPhoneNumber();
                search(number);
                super.callIncoming(callId);
            }
        });

2.在地址簿中搜索

public void search(String number) throws PIMException{
        PIM pim = PIM.getInstance();
        BlackBerryContactList contacts = (BlackBerryContactList) pim
        .openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
        Contact template = contacts.createContact();
        template.addString(Contact.TEL, Contact.ATTR_MOBILE, number);
        Enumeration matches = contacts.items(template);
        if (matches.hasMoreElements())
        {
            Contact contact = (Contact)matches.nextElement();
            if (contact.countValues(Contact.NAME) > 0){
                String[] name = contact.getStringArray(Contact.NAME, 0);

                synchronized (Application.getEventLock()) {
                    UiEngine ui = Ui.getUiEngine();
                    Screen screen = new Dialog(Dialog.D_OK,
                            name[Contact.NAME_GIVEN], Dialog.OK, Bitmap
                            .getPredefinedBitmap(Bitmap.EXCLAMATION),
                            VerticalFieldManager.VERTICAL_SCROLL);
                    ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_QUEUE);
                }
            }

        }
    }

<强>更新 在黑莓os 6 您可以使用PhoneCall.getContact()方法查找活动呼叫的联系人。

相关问题