简体   繁体   中英

attaching image to blackberry Email through code

I have a problem attaching an image to a blackberry email.

In my code I can attach a png image taken with the camera and it is visible in attachments, but when I click on the send email button I get an error:

Email service does not support these types of attachments. Change the Send-Using field, or change the attachments

My code is:

try {
    FileConnection file = (FileConnection)Connector.open( FILE_NAME );
    if(file.exists())
    {
        InputStream stream = file.openInputStream();
        buf = IOUtilities.streamToBytes(stream);
        stream.close();
        file.close();
        SupportedAttachmentPart sap = new SupportedAttachmentPart(mp,"image/png","collision.png",buf);
        //SupportedAttachmentPart sap = new SupportedAttachmentPart(mp,jpegImage.getMIMEType() ,"collision.jpg",jpegImage.getData() );  
        TextBodyPart tbp = new TextBodyPart(mp,"Attachment test");
        TextBodyPart name = new TextBodyPart(mp,"Name:"+Name.getText().toString());

        mp.addBodyPart(tbp);
        mp.addBodyPart(sap);
        mp.addBodyPart(name);

        Folder folders[] = Session.getDefaultInstance().getStore().list(Folder.SENT);

        Message message = new Message(folders[0]);

        try {
            Address toAdd = new Address("xyz_123@yahoo.com","test email");
            Address toAdds[] = new Address[1];
            toAdds[0] = toAdd;
            message.addRecipients(Message.RecipientType.TO,toAdds);
            message.setContent(mp);
            message.setSubject("Service Request via Blackberry app");

            Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(message));

            //Transport.send(message);
        } 
        catch (Exception e) {
            Dialog.inform(e.toString());
        }
    }

在模拟器上这是正常现象,请在真实设备上尝试,它将正常工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM