25
3: Working with attachments
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® 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.
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 messages 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 messages 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.
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.
>
Invoke
AttachmentHandlerManager.addAttachmentHandler()
.
AttachmentHandlerManager m = AttachmentHandlerManager.getInstance();
CustomAttachmentHandler ah = new CustomAttachmentHandler();
m.addAttachmentHandler(ah);
Task
Steps
Retrieve the contents of an attachment. >
Invoke
SupportedAttachmentPart.getContent().
String s = new String((byte[])p.getContent());
Содержание JAVA DEVELOPMENT ENVIRONMENT - - DEVICE APPLICATIONS INTEGRATION - DEVELOPMENT GUIDE
Страница 1: ...BlackBerry Java Development Environment Version 4 6 0 BlackBerry Device Applications Integration Guide...
Страница 4: ......
Страница 7: ......
Страница 10: ...10 BlackBerry Device Applications Integration Guide...
Страница 12: ...12 BlackBerry Device Applications Integration Guide...
Страница 50: ...50 BlackBerry Device Applications Integration Guide...
Страница 56: ...56 BlackBerry Device Applications Integration Guide...
Страница 65: ......
Страница 66: ...2008 Research In Motion Limited Published in Canada...