Would you like to tell us how we are doing?

You bet No thanks

Sorry about the red box, but we really need you to update your browser. Read this excellent article if you're wondering why we are no longer supporting this browser version. Go to Browse Happy for browser suggestions and how to update.

Send media sample app

The send media sample application demonstrates how to register an application as a content handler for any supported image or video file types on the BlackBerry device.

When a user turns on the BlackBerry device, the sample application registers itself as a content handler for the following content types:

  • image/bmp
  • image/png
  • video/jpeg
  • video/3gpp
  • video/mp4

When you view a file that is any of the preceding content types in the camera application or video camera application on the BlackBerry device, or if you click a file that is any of the preceding content types in the media application, a menu item, Send to demo app, becomes available. When you click this menu item, the sample application opens the picture or video file.

File name



This file contains the entry point for the application and contains the method register(), which specifies the content handler's properties and registers the sample application as a content handler with the Registry.

This file also contains the implementation of the RequestListener interface. The implementation is just the single method, invocationRequestNotify(), which is invoked when an invoking application (such as the camera application) sends an Invocation event to the sample application. This method retrieves the request, checks whether the file to be opened is an image or a video file and calls the appropriate helper method to open the file.

This file contains helper methods to display the image or video file that the invoking application selects.


This project file specifies that the sample application starts running when the BlackBerry device is turned on and that the sample application must register itself as a content handler.

To do this, the project file also specifies that the String "startup" will be passed to the main() method of the sample application when the BlackBerry device is turned on. The sample application's main() method checks if this String has been passed in and, if it has, invokes the register() helper method.

This sample features the following classes:


This class provides methods to invoke, register, unregister, and query information about content handlers. Your application can register zero or more content types (for example, image/bmp), suffixes, and actions.

The application gains access to the registry by invoking the getRegistry() method and passing in a classname parameter. The classname parameter is a String that uniquely identifies the application with the Registry class.

The Registry class also provides methods to access the ContentHandlerServer class using the getServer() method. Like the getRegistry() method, the getServer() method requires a classname parameter that uniquely identifies the application with the ContentHandlerServer class.

The sample application uses this class to register this application as a content handler for the content types image/bmp, image/png, image/jpeg, video/3gpp, and video/mp4.

The sample application passes in the String, com.rim.samples.device.sendmediademo.SendMediaDemo, as the classname parameter in the getRegistry() and getServer() methods to uniquely identify this application in the Registry and the ContentHandlerServer, respectively.


This class contains methods to access the information that is contained in the request that an invoking application passes to a content handler. The results of the request are then passed to the content handler application through the ContentHandlerServer.getRequest() method.

The sample application retrieves the invocation from the invoking application (for example, the camera application) through the ContentHandlerServer using the ContentHandlerServer.getRequest() method in the sample application's invocationRequestNotify() method.

The sample application then uses the getType() method to extract the file type that the invoking application has sent to the sample application. After checking whether the file is an image or a video file, the sample application prepares the file for display. Depending on the file type, the application must perform different actions to display the file; however, in both cases, the location of the file to be displayed is retrieved using the getURL() method.


This class provides functionality to map actions to action names. An ActionNameMap object is one of the parameters that the the Registry.register() method requires.

The ActionNameMap constructor takes two String arrays, actions and actionnames, as parameters. The ActionNameMap object maps the String, actions, at position i to the actionnames String at position i. For an application that registers itself as a content handler on the BlackBerry device, the actions parameter should be one of the constants that the ContentHandler interface in the javax.mocroedition.content package provides. This parameter defines the functionality that the content handler provides. For example, if your content handler can print the file that is being handled, you would add ContentHandler.ACTION_PRINT as one of the entries in the actions array. Other applications can find your content handler if they use the Registry.findHandler() method to search for a content handler on the BlackBerry device that has registered itself with the appropriate action constant.

The ActionNameMap constructor also takes in a locale parameter. This is a required parameter that must correspond with the locale syntax conventions that are defined in the ContentHandler class.

In the sample application, the ActionNameMap object is created in the sample application's register() method. The Registry.register() method takes an ActionNameMap array as a parameter, therefore the sample application creates the ActionNameMap object as an array with a single entry.

The ActionNameMap object maps the ContentHandler.ACTION_SEND action to the name of the menu item Send to demo app. Typically, the ContentHandler.ACTION_SEND constant signifies that the handler application provides functionality to send the content by email messaging or instant messaging. The feature that this application demonstrates would likely not be used to send content by email messaging or instant messaging, but would be used to handle the content in an application-specific way, such as sending the content over an HTTP connection.

Install the sample app

Visit http://www.blackberry.com/go/sendmediasample to download the sample application.

Extract the sendmediademo.zip file.

On the taskbar, click Start > Programs > Research In Motion > BlackBerry JDE 4.7.0 > JDE.

Open the workspace that you want to add the sample application to.

In the workspace tree, right-click the folder that you want to add the sample application to.

Click Add project to <workspace folder>.

In the Add project to <workspace> dialog box, browse to the folder where you extracted the sample application.

Click the SendMediaDemo.jdp file.

Click Open.

The sample app is also available in github.

Run the sample app

In the workspace where you added the sendmediademo project, right-click sendmediademo.

Click Build project.

On the taskbar, click Start > Applications > Research in Motion > BlackBerry JDE 4.7.0 > Device Simulator.

On the Home screen of the BlackBerry Smartphone Simulator, click the Camera icon.

In the Select camera image - BlackBerry Smartphone Simulator dialog box that appears (when you do not have a webcam connected to your computer), click Cancel.

Click the Menu key.

Click View pictures.

Click an image to open it.

When the image opens in the camera application, click the Menu button.

Click Send to demo app.

The image is sent to the Send Media Demo application and is opened.