Develop applications for the BlackBerry

Want to develop apps for the BlackBerry handheld devices on the market in Australia? Get started with this primer from Builder Australia's David McAmis.

This article originally appeared in Builder Australia.

The BlackBerry Personal Information Manager (PIM) is a portable device that connects users to corporate e-mail and other systems across a wireless connection, providing instant, 24x7 access to business critical information.

Here in Australia, BlackBerry devices have been available for a while exclusively through Telstra, but that is all about to change, with the introduction of BlackBerry devices and services from a number of other wireless providers such as Vodafone coming soon.

To start, you will need to have the latest edition of the Java 2 Platform SDK (currently, which you can download from Sun's Web site. The SDK installation will take a few minutes and requires approximately 120 MB of hard drive space, but will provide all of the tools you need to compile your BlackBerry applications.

Next, you will need to install the BlackBerry Java Development Environment (currently version 3.7), which you can download from the BlackBerry Developer Web site. This installation is also straightforward and requires 77 MB of hard drive space. Use the Complete installation option to install all of the documentation, sample code, and program files, as well as simulators for client and server components.

You can use the client simulator to test how your application will behave when loaded onto a BlackBerry device, as shown in Figure A.

The tools will be installed in the Start menu under a program group named Research In Motion, with submenus containing all of the BlackBerry tools. From the submenu, select the option to open the JDE, which will open the window shown in Figure B with a workspace and a number of sample applications that you can view.

Creating a new application

To create your own workspace, select File > New Workspace and give your workspace a name and location. Workspaces have a .JDW extension, and a workspace file will be created in the location you specify.

Next, you will want to create a project.

In this example, we are going to walk through the classic "Hello World" project to demonstrate how the BlackBerry JDK works. To create a new project, select Project | Create A New Project. Enter a name for your project, as well as a file path. For this example, we'll be original and call the project "Hello World."

Now, that we have created a project, we need to add some Java code to it. To add this code, we'll create an external .JAVA file that contains the code we need. We'll name this file "HelloWorld.JAVA" and you can create it using Notepad or the text editor of your choice.

Normally, in a Java application, you would use the import statement to add the different Java classes that you wanted to reference. Since the BlackBerry uses Java 2 Mobile Edition, all of the classes from J2ME are available to you. In addition, there are a number of classes that are unique to BlackBerry that we need to add to interface with the user interface, device resources, etc.

So the first part of your code would look something like this:

Editor's note:

You can find a description of all of these classes in the documentation that is included with the JDK.

Next, we need to create a custom class for our Hello World application, create the application, and use the "pushScreen" method to make our application appear as the active application.

And finally, we can get down to actually putting in the elements we would like to see on the screen, starting with the default menu options and a close option. We will also use the setTitle method to set the title that should appear at the top of our application.

We also need to set the behavior for when the user closes the application. In this case, we are going to trap for the Escape button on the side of the BlackBerry device, and when the user closes the application or presses the Escape button, we'll display some text and close the application using the code below:

With your file added to the project, our next order of business is to add an icon that will appear on the BlackBerry desktop to launch our application. Your icon should be 28 x 28 pixels and should be saved in a single-layer PNG or GIF file. For this example, we've created our own icon file, and you can easily do the same using your favorite graphics or icon editing program.

To add the icon, right-click on your project and select Add File To Project; then browse and select the icon file provided.

Building and deploying your application

With all of the components in place, we're ready to build and deploy your application to your BlackBerry device. From within the JDE, select Debug | Go to start the build process. The progress of the build will appear in the status window at the bottom of the JDE.

Once the build process has completed successfully, the client simulator will open and display your application, as shown in Figure C.

You can use the simulator to test your application and ensure that the program runs as expected. In this example, you should be able to use the controls on the simulator to scroll to your program icon and use the return key to launch it. It should display the text "Hello World" on the BlackBerry screen. To exit the program, use your mouse to click the Escape button on the side, or use the [Esc] key on your keyboard.

Deploying your application

Since we've developed this application using the BlackBerry JDE, deployment is pretty easy. When you build your application, the development environment builds the .JAD (Java Application Descriptor) file that is required to distribute your application, along with the required .COD files.

The easiest way to distribute these files is to make them available on a Web server that your BlackBerry users can access. Before you can publish these files, you'll need to do some configuration on the Web server to make this happen. On your Web server MIME settings, you'll need to ensure that you have the following settings:

.JAD         text/vnd.sun.j2me.ap-descriptor
.COD         application/vnd.rim.cod

You can then give users a URL that points to the .JAD file. When they browse this file from their BlackBerry, it will trigger the installation of the program you've created.

This is a very simple application example—given that the Blackberry uses Java, you can develop just about any application that you can imagine. If you want to know more about developing for this platform, there are a number of resources for BlackBerry developers, including the BlackBerry Developer Web site and a number of third-party sites as well. The BlackBerry Developer site has a comprehensive knowledge base of articles, as well as developer documentation and forums.

Editor's Picks

Free Newsletters, In your Inbox