Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Delivering attachment contents to a BlackBerry smartphone

by BlackBerry Development Advisor on ‎02-16-2010 12:21 PM - edited on ‎07-27-2011 01:11 PM by Administrator (9,710 Views)

Summary

 

This article applies to the following:

  • BlackBerry® smartphones based on Java® technology

Description

 

There are two methods that can be used to access email attachments in a BlackBerry Java Application. The first method is to create a custom attachment handler. This is supported in BlackBerry® Device Software 3.6 and later. The second method is to create a content handler using the Java Specification Request (JSR) 175 Content Handler.

 

AttachmentDownloadManager

 

The AttachmentDownloadManager class was added in version 5.0 of the BlackBerry API set.  

This class provides the ability to prgrammatically download email attachments for incoming message.  It does not support forwarded or sent messages.  Attachments can be downloaded regardless of its viewable state. That is, an attachment can be of type SupportedAttachmentPart or UnsupportedAttachmentPart.  You can implement DownloadProgressListener to receive downloading outcomes.

 

 

 

JSR 175 Content Handler

 

Support for JSR 175 Content Handler application programming interfaces (APIs) was introduced with BlackBerry Device Software 4.5. To use these APIs, the BlackBerry smartphone must be running BlackBerry Device Software 4.5 or later. Once an application is registered as a content handler for a specific file, the BlackBerry smartphone user sees a Download Now menu option when they view an email message with an attachment (and the attachment file type matches the registered content handler). The BlackBerry smartphone user can select this menu option to download the attachment, which is then supplied to the application. For an example, see the chapidemo included with the BlackBerry® Java® Development Environment (BlackBerry JDE) and the BlackBerry® JDE Plug-in for Eclipse®.

 

Custom Attachment Handler

 

You can create an application to have the BlackBerry smartphone process a specific attachment type, or deliver data to a BlackBerry smartphone application as an email attachment.

 

By default, email attachments are not delivered or stored on the BlackBerry smartphone. To force an email attachment to be sent or stored on the BlackBerry smartphone, add the prefix x-rimdevice to the attachment name.

 

Note: Secure Multipurpose Internet Mail Extensions (S/MIME) attachments are not delivered to the BlackBerry smartphone, regardless of whether they have the x-rimdevice prefix.

 

Maximum attachment size for x-rimdevice attachments


Service/Version BlackBerry Device Software version Maximum size (KB) 
BlackBerry® Enterprise Server earlier than software version 4.0 earlier than 4.0 32
BlackBerry Enterprise Server earlier than software version 4.0 4.0 and later 32
BlackBerry Enterprise Server software version 4.0 and later earlier than to 4.0 32
BlackBerry Enterprise Server software version 4.0 and later 4.0 and later 64
BlackBerry® Internet Service earlier than to 4.0 32
BlackBerry Internet Service 4.0 and later 64

For BlackBerry smartphones running BlackBerry Device Software 4.0, the 64 KB maximum size limit includes the attachment, message headers, and the message body. Therefore, the attachment size should be lower than 59 KB. Attachments larger than this are partially delivered to the BlackBerry smartphone. The files are truncated at the maximum size.

 

The following code sample shows how to create an Attachment Handler on the BlackBerry smartphone. This application adds a View File menu option when the BlackBerry smartphone user views an email message that contains a Wireless Markup Language (WML) file attachment.

 

 

/*
* My Attachment Viewer
*
*/

package com.samples.attachmentViewer;

import net.rim.blackberry.api.mail.*;
import net.rim.blackberry.api.mail.event.*;
import net.rim.device.api.system.*;

class MyViewer extends Application implements AttachmentHandler
{

public static void main(String args[])
{
MyViewer theApp = new MyViewer();
}

public MyViewer()
{
//Add this AttachmentHandler to the AttachmentHandlerManager
AttachmentHandlerManager m = AttachmentHandlerManager.getInstance();
m.addAttachmentHandler(this);
}

//Called when a new email message arrives to see if
//it is supported by this AttachmentHandler (this sample
//supports wml). If it is true then the menu item will be
//shown in the message screen.

public boolean supports(String contentType)
{

boolean val;

if (contentType.toLowerCase().indexOf("wml") != -1)
val = true;
else
val = false;

return val;
}

//Then menu item that will appear from the message screen
public String menuString()
{
return "View File";
}

//Runs when the user selects the above defined menu item
public void run(Message m, SupportedAttachmentPart p)
{
//Perform required processing on your attachment here.
//Get the attachment filename.
System.out.println("WML filename: " + p.getFilename());
//Get the attachment size.
System.out.println("Attachment size is: " + p.getSize());
//Get the contents of the attachment.
byte[] temp = (byte[])p.getContent();
String data = new String(temp);
System.out.println("Attachment Content: " + data);
}
}

 

 

Comments
by Developer on ‎07-26-2011 08:29 PM

AttachmentDownloadManager has been available since API 5.0, not 6.0.

by Administrator on ‎07-27-2011 01:10 PM

Good catch.  I'll update the article.

by Developer ‎11-09-2012 03:47 AM - edited ‎11-09-2012 04:06 AM

Using this getContent method of AttachmentHandler, i am not getting the content of the attachment.. how to retreive the content of the attachment..

by Administrator on ‎11-09-2012 09:13 AM

Ensure x-rimdevice is prefixed to the attachment filename and that the attachment does not use an extension natively supported on a BlackBerry Smartphone.

Users Online
Currently online: 29 members 1,001 guests
Please welcome our newest community members: