Working with attachments
To open incoming message attachments and create outgoing attachments on the BlackBerry® device, use the mail
API. A separate
BodyPart
Create an attachment handler
The BlackBerry® Enterprise Server Attachment Service receives all attachments first. Third-party attachment
handlers cannot override the default BlackBerry device behavior. See the BlackBerry Enterprise Server
Maintenance and Troubleshooting Guide for more information about the BlackBerry Enterprise Server Attachment
Service.
Task
Define a custom attachment handler.
Register the accepted MIME types
when the BlackBerry® device receives
an attachment.
Define the associated menu item string
to display in the messages list when the
BlackBerry device user selects an
attachment.
Define attachment processing.
Register an attachment.
Retrieve attachments
Task
Retrieve the contents of an attachment. >
on a
Multipart
message represents a message attachment.
Steps
AttachmentHandler
>
Implement the
supports(String)
>
Implement
public boolean supports(String contentType) {
return (contentType.toLowerCase().indexOf("contenttype") != -1 ? true :
false);
}
menuString().
>
Implement
public String menuString() {
return "Custom Attachment Viewer";
}
run()
>
Implement
this action invokes the
public void run(Message m, SupportedAttachmentPart p) {
// Perform processing on data.
Screen view = new Screen();
view.setTitle(new LabelField("Attachment Viewer"));
view.add(new RichTextField(new String((byte[])p.getContent())));
}
When registering a custom attachment handler, the attachment name must be prefixed with "x-
rimdevice" for the attachment to be sent and stored on the BlackBerry device.
AttachmentHandlerManager.addAttachmentHandler()
>
Invoke
AttachmentHandlerManager m = AttachmentHandlerManager.getInstance();
CustomAttachmentHandler ah = new CustomAttachmentHandler();
m.addAttachmentHandler(ah);
Steps
SupportedAttachmentPart.getContent().
Invoke
String s = new String((byte[])p.getContent());
interface.
.
. When a BlackBerry device user selects a menu item from the messages list,
run()
method.
3: Working with attachments
.
25