views:

477

answers:

3

I wanted to get the list of all names and their corresponding email address from the contact list in blackberry JDE 4.7 can anyone help with the code for getting the above mentioned things..

Thanks in advance...

+4  A: 

try this code:

public Scr() {
    Vector v = getContacts();
    Enumeration iterator = v.elements();
    while (iterator.hasMoreElements()) {
        String[] contact = (String[]) iterator.nextElement();
        for (int i = 0; i < contact.length; i++)
            add(new LabelField(contact[i]));
    }

}

private Vector getContacts() {
    Vector result = new Vector();
    try {
        BlackBerryContactList contactList = (BlackBerryContactList) PIM
                .getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
        Enumeration enumx = contactList.items();
        while (enumx.hasMoreElements()) {
            BlackBerryContact c = (BlackBerryContact) enumx.nextElement();
            String[] contact = new String[2];
            if (contactList.isSupportedField(BlackBerryContact.NAME)) {
                String[] name = c.getStringArray(BlackBerryContact.NAME, 0);
                String firstName = name[Contact.NAME_GIVEN];
                String lastName = name[Contact.NAME_FAMILY];
                contact[0] = firstName + " " + lastName;
            }
            if (contactList.isSupportedField(BlackBerryContact.EMAIL)) {
                StringBuffer emails = new StringBuffer();
                int emailCount = c.countValues(BlackBerryContact.EMAIL);
                for (int i = 0; i < emailCount; i++) {
                    String email = c.getString(BlackBerryContact.EMAIL, i);
                    if (email != null) {
                        emails.append(email.trim());
                        emails.append("; ");
                    }
                }
                contact[1] = emails.toString();
            }
            result.addElement(contact);
        }
    } catch (PIMException ex) {
        ex.printStackTrace();
    }
    return result;
}
Max Gontar
A: 

Hi all

am doing contact sync application for blackberry i can get photo through the getbianry method , if i sent it to my server and i get it back i cant set or add that binary to contacts while Downloading i get binary like this [B@4a5910e0 , am using KXML so i get this binary as a string after that i convert this string to bytes using String.getbytes() or String.getbytes(UTF8) method then i encode it and add this binary to contact it gives error any suggestions pls?

java.lang.IllegalArgumentException: Image type is not supported

      byte[] raw="[B@4a5910e0".getbytes();

byte encoded[] = Base64OutputStream.encode(raw, 0, raw.length, false, false); contact .addBinary (Contact.PHOTO, Contact.ATTR_NONE, encoded, 0, encoded.length);

bbdeveloper
A: 

I'm also having the same problem. I keep getting Image type is not supported when adding an image to a contact via addBinary(). I'm opening my image from the file system on the device and then using EncodedImage to get the data (getData()). Why am I getting this error? Thanks!