Troubleshooting guide
161
10: Using the messages application
Send a message with an attachment
Retrieve information about the
attachment.
> Invoke the methods of the SupportedAttachmentPart class. The
SupportedAttachmentPart class represents an attachment with a corresponding viewer on
the BlackBerry® device. An
UnsupportedAttachmentPart represents an attachment that
does not have a viewer on the BlackBerry device.
public void run(Message m, SupportedAttachmentPart p) {
...
String name = p.getName();
int size = p.getSize();
}
Task Steps
Create a multipart message.
> Create a new Multipart object.
byte[] buf = new byte[256]; // The attachment.
MultiPart multipart = new MultiPart(); // Default type of multipart/
mixed.
Create each component of the
attachment.
>Create a SupportedAttachmentPart object, designating the Multipart object as its
parent.
SupportedAttachmentPart attach = new SupportedAttachmentPart(
multipart, "application/x-example", "filename", data);
Add each SupportedAttachmentPart
object to the multipart object.
>Invoke addBodyPart(SupportedAttachmentPart) on that object.
multipart.addBodyPart(attach); // Add the attachment to the multipart.
Set the content of the attachment. >Invoke setContent(Multipart) on the Message object and pass in the Multipart
object as its parameter.
msg.setContent(multipart);
Send the message. >Invoke Transport.send().
Transport.send(msg);
Task Steps