Troubleshooting guide

160
BlackBerry Java Development Environment Development Guide
Working with attachments
To open incoming message attachments and create outgoing attachments on the BlackBerry® device, use the
mail API. A separate
BodyPart on a Multipart message represents a message attachment.
Create an attachment handler
The BlackBerry® 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 Attachment Service.
Retrieve attachments
Task Steps
Define a custom attachment handler. > Implement the AttachmentHandler interface.
Register the accepted MIME types
when the BlackBerry device receives an
attachment.
> Implement supports(String).
public boolean supports(String contentType) {
return (contentType.toLowerCase().indexOf("contenttype") != -1 ? true
: false);
}
Define the associated menu item string
to display in the message list when the
BlackBerry device user selects an
attachment.
> Implement menuString().
public String menuString() {
return "Custom Attachment Viewer";
}
Define attachment processing. > Implement run(). When a BlackBerry device user selects a menu item from the message list,
this action invokes the
run()method.
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())));
}
Register an attachment. >Invoke addAttachmentHandler().
AttachmentHandlerManager m = AttachmentHandlerManager.getInstance();
CustomAttachmentHandler ah = new CustomAttachmentHandler();
m.addAttachmentHandler(ah);
Task Steps
Retrieve the contents of an attachment. >Invoke getContent().
String s = new String((byte[])p.getContent());