开发者

Reg. Contacts extracting

开发者 https://www.devze.com 2023-01-10 20:08 出处:网络
How to check a incoming number whether that is existing in bla开发者_如何学运维ckberry contact list or not.. if it is there i want to display its contact name..

How to check a incoming number whether that is existing in bla开发者_如何学运维ckberry contact list or not.. if it is there i want to display its contact name..

Thanks in advance..


i think this will help you
1. add phone listener

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

2.search in the address book

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

        }
    }

update: in blackberry os 6 You can look up the contact for an active call by using the PhoneCall.getContact() method.

0

精彩评论

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