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

Posts: 28
Registered: ‎12-18-2008
My Device: Not Specified

email an image as an attachment...

I need to attach an image to an email and send. The following is the part of my code i used to read the image from the device storage and add to the attachment. But it's not working..  


FileConnection fconn = (FileConnection)Connector.open("file:///SDCard/BlackBerry/pictures/IMG00017.jpg");
                        input = fconn.openInputStream();
                        buffer = new DataBuffer();
                        byte[] temp = new byte[1024];
                        for( ;; ) {
                            int bytesRead = input.read( temp );
                            if( bytesRead == -1 ) {
                            buffer.write( temp, 0, bytesRead );
                      SupportedAttachmentPart sap = new SupportedAttachmentPart(mp,".jpg","file.jpg",buffer.getArray());


Can anyone correct my code if there is any problem? Or can you suggest another solution?



Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: email an image as an attachment...


Check with size of image, Some devices have problem reading a bigger image.


Try sending a small image.


Check you getting any exception and you can use device debugger too for tracing.



Use Search. "Accept Solution" If the problem is resolved.