Retrieve the contact that is associated with a completed call

You can retrieve the contact that is associated with a completed call from the call log on a BlackBerry® device.
  1. Import the required classes and interfaces.
    import javax.microedition.pim.Contact;
    import net.rim.blackberry.api.pdap.BlackBerryContact;
    import net.rim.blackberry.api.phone.phonelogs.PhoneCallLogID;
  2. Retrieve the caller ID information for a call from the call log.
    PhoneCallLogID callLog = new PhoneCallLogID(phoneNum);
  3. Retrieve the associated contact by invoking PhoneCallLogID.getContact(). The getContact() method searches all contact lists on the BlackBerry device for a contact that matches the caller ID information. The method returns null if there is no matching contact.
    BlackBerryContact contact = callLog.getContact();

Code sample

String phoneNum = "519-555-0151";

PhoneCallLogID callLog = new PhoneCallLogID(phoneNum);
BlackBerryContact contact = callLog.getContact();
            
if (contact != null)
{
   String[] name = contact.getStringArray(Contact.NAME, 0);
   add(new RichTextField("The matching contact is " + name[Contact.NAME_GIVEN] 
      + " " + name[Contact.NAME_FAMILY]));
}
else
{
   add(new RichTextField("There is no matching contact"));
}

Was this information helpful? Send us your comments.