X
Business

BlackBerry, anyone?

Mobile applications are on the rise, and with the BlackBerry platform now available in Asia, there is one more platform for developers to exploit. Here's a primer.
Written by David McAmis, Contributor

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 like Vodafone coming soon.

To start, you will need to have the latest edition of the Java 2 Platform SDK (currently 1.4.2.04) which you can download from Sun’s Web site. The SDK installation will take a few minutes and requires approximately 120mb 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 straight-forward and requires 77mb 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 below in Figure A


Figure A
The BlackBerry Client Simulator

The tools will be installed in the Start menu under a program group named “Research in Motion”, with sub-menus containing all of the BlackBerry tools. From the sub-menu, 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.


Figure B
The JDE Window

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 are going to be original and call the project “Hello World”

Now that we have created a project, we need to add some Java code to our project. To add this code, we are going to create an external .JAVA file that contains the code we need. We are going to 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 are also going to use the setTitle method to set the title that should appear the top of our application.

We also need to set the behaviour 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 they close the application or press the Escape button, we are going to display some text and close the application using the code below:

With your HelloWorld.java 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 28x28 pixels and should be saved in a single-layer PNG or GIF file. For this example, we have created our own icon file and you can easily do the same using your favourite graphics or icon editing program.

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

Building and Deploying your Application
With all of the components in place, we are 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 below in Figure C


Figure C
The simulator with the application running

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 have developed this application using the Blackberry JDE, deployment is pretty easy. When you build your application, the development environment builds the .JAD file that is required to distribute your application JAD stands for "Java Application Descriptor" and along with the .COD files that the JDE generates.

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 will need to do some configuration on the Web server to make this happen. On your Web server MIME settings, you will 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 have 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.

Further reading:




Editorial standards