2010-08-05 106 views
0

如何檢查來電號碼是否是在黑莓的聯繫人列表中現有的或不..如果它的存在,我想顯示其聯繫人的姓名..註冊聯繫方式提取

在此先感謝..

+1

如果來電號碼是現有號碼,設備會自動顯示他的名字。 – Vivart 2010-08-05 10:20:02

回答

2

我認爲這將幫助你在地址簿中
1.添加電話監聽

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

2.search

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

     } 
    } 

更新: in blackberry os 6 您可以使用PhoneCall.getContact()方法查找活動呼叫的聯繫人。