26
BlackBerry Device Applications Integration Guide
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.
Task
Steps
Create a multipart message.
>
Create a new
Multipart
object.
byte[] data = 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 provide as a parameter the
Multipart
object.
msg.setContent(multipart);
Send the message.
1.
Invoke
Session.getTransport()
and store the returned object in a variable of type
Transport
. The
Transport
object represents the messaging transport protocol.
Transport trans = Session.getTransport();
2. Invoke
trans.send(Message).
try {
trans.send(msg);
} catch(MessagingException e) {
System.out.println(e.getMessage());
}
Task
Steps
Summary of Contents for JAVA DEVELOPMENT ENVIRONMENT - - DEVICE APPLICATIONS INTEGRATION - DEVELOPMENT GUIDE
Page 4: ......
Page 7: ......
Page 10: ...10 BlackBerry Device Applications Integration Guide...
Page 12: ...12 BlackBerry Device Applications Integration Guide...
Page 50: ...50 BlackBerry Device Applications Integration Guide...
Page 56: ...56 BlackBerry Device Applications Integration Guide...
Page 65: ......
Page 66: ...2008 Research In Motion Limited Published in Canada...