Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 69
Registered: ‎07-30-2009
My Device: Not Specified

Illegal argument exception while adding CONTACT.PHOTO

HI all

 

               i can read and create contact photos  within device , i wish to save my contact photos in my server so i sent readed bytes to my server.  i am facing a strange issue  while creating photo using recived bytes from server i get an

illgal argument exception:Image format is not supported  error , using recived bytes i cant create even an encoded image and bitmap!  i got this code from pim contact interface api

 

 while reading photo bytes i got  data like this [B@c342900e , whats he problem here? any suuggestion please.

 

public void setPhoto() throws IOException {
byte[] photo = getSamplePhoto();
byte[] photoEncoded = Base64OutputStream.encode(photo, 0, photo.length, false, false);
if (_contact.countValues(Contact.PHOTO) > 0) {
_contact.setBinary(Contact.PHOTO, 0, PIMItem.ATTR_NONE, photoEncoded, 0, photo.length);
} else {
_contact.addBinary(Contact.PHOTO, PIMItem.ATTR_NONE, photoEncoded, 0, photo.length);
}
}

public byte[] getPhoto() throws IOException {
if (_contact.countValues(Contact.PHOTO) > 0) {
byte[] photoEncoded = _contact.getBinary(Contact.PHOTO, 0);
return Base64InputStream.decode(photoEncoded, 0, photoEncoded.length);
} else {
return null;
}
}

Highlighted
New Contributor
Posts: 7
Registered: ‎09-21-2011
My Device: Torch 9800
My Carrier: Software Developer

Re: Illegal argument exception while adding CONTACT.PHOTO

Hello,

I need your help, I want to show contact photo as an bitmap on screen. I am using the same code which you have used. and like

_photo = new PhotoExample(_contact);
byte[ ] b = _photo.getPhoto();

/////////////////////////////////////////////

photoExample class

public byte[] getPhoto() throws IOException {
        if (_contact.countValues(Contact.PHOTO) > 0) {
            byte[] photoEncoded = _contact.getBinary(Contact.PHOTO, 0);
            return Base64InputStream.decode(photoEncoded, 0, photoEncoded.length);
        } else {
            return null;
        }
    }

 it always returns null from the else case of getPhoto() method. please suggest me the correct way.

I need to show  bitmap image on the screen of contact photo.