Tuesday, November 5, 2024

Kick Start J2ME (TM) Development with BlackBerry

If you are looking to expand your user base, you may want to consider looking into porting your game or application to the BlackBerry handsets.

With over one million units sold by RIM, I am sure there is immense potential to increase your user base and profit. Fortunately for us, BlackBerry supports Java and, more specifically, J2ME. The remainder of this article briefly introduces you to development on BlackBerry and some of the differences compared to developing J2ME applications on mobile phones. There is an assumption you have developed with J2ME, are using an IDE such as Eclipse, and already have an understanding of mobile development in general.

Development Environment

First of all, RIM provides their own IDE, called the Java Development Environment (JDE). It comes with a development environment (debugger, context sensitive help, and so forth), e-mail simulator, device simulator, and Internet gateway simulator. The IDE itself is similar to any other IDE you’ve probably used in the past, such as Eclipse, JBuilder, or Sun One (Forte). Both the e-mail simulator and Internet gateway simulator are used to simulate an enterprise environment. One thing I found extremely helpful is the capability of debugging directly with an actual device via USB. The JDE currently supports MIDP 1.0 and CLDC 1.0. All in all, there is nothing really special here or different from what you are probably used to when developing with J2ME. One additional note: You don’t have to use the JDE; you can build .cod files through CLI if you want to continue using build scripts such as ANT and ANTENNA.


JDE in Action

Differences?

Okay, what are the differences? The JDE produces both the JAR and JAD files, but it also creates an additional file with the extension .cod. This file is needed when deployment is done through OTA. This brings up another point when deploying through OTA: Your server must be configured to support the following file types for BlackBerry:

  • .jad-text/vnd.sun.j2me.app-descriptor
  • .cod-application/vnd.rim.cod
  • The JAD file itself contains BlackBerry-specific attributes; the following is an example of what one looks like:

    Manifest-Version: 1.0
    RIM-COD-Module-Name: MyTestApp
    RIM-COD-Module-Dependencies: net_rim_os,net_rim_cldc
    RIM-COD-Creation-Time: 104940394
    MIDlet-Jar-URL: unknown
    RIM-COD-URL: MyTestApp.cod
    RIM-COD-Size: 15899
    MicroEdition-Configuration: CLDC-1.0
    MIDlet-Version: 1.00
    MIDlet-Name: MyTestApp
    MIDlet-Vendor: ABC Inc.
    MicroEdition-Profile: MIDP-1.0

    It is probably best to allow the JDE to generate the JAD file and then make the appropriate changes afterwards. Now is probably a good time to mention that, even though your application can be compiled and run when it exceeds 64KB, it is more then likely that users will have difficulties downloading the application via OTA. Breaking down your program into smaller chunks of 64KB or less will solve this problem. A sample snippet of what the JAD file looks like follows:

    ...
    RIM-COD-URL-1: MyTestAppLib.cod
    RIM-COD-SIZE-1: 4039
    RIM-COD-URL-2: MyTestApp.cod
    RIM-COD-SIZE-2: 55540
    ...

    You will notice that the Lib is defined first; this is required for OTA to work properly. Please consult the JDE user guides on how to create libraries.

    Because it is more than likely that BlackBerry users are given a sync cable at the point of purchase, it won’t be uncommon for users to install and uninstall applications via USB. In the JDE, there is an option to generate another type of file with the extension ALX. If you open it up, it’s nothing more then a XML file.

    <loader version="1.0">
    &nbsp&nbsp <application id="MyTestApp">
    &nbsp&nbsp&nbsp <name>MyTestApp</name>
    &nbsp&nbsp&nbsp <description>MyTestApp</description>
    &nbsp&nbsp&nbsp <version>1.0</version>
    &nbsp&nbsp&nbsp <vendor>ABC Ltd</vendor>
    &nbsp&nbsp&nbsp <copyright>Copyright (c) 2004 ABC Ltd</copyright>
    &nbsp&nbsp&nbsp <fileset Java="1.0">
    &nbsp&nbsp&nbsp&nbsp <files>MyTestApp.cod</files>
    &nbsp&nbsp&nbsp </fileset>
    &nbsp&nbsp&nbsp <application id="MyTestAppLib">
    &nbsp&nbsp&nbsp&nbsp <name>MyTestAppLib</name>
    &nbsp&nbsp&nbsp&nbsp <description></description>
    &nbsp&nbsp&nbsp&nbsp <version>1.0</version>
    &nbsp&nbsp&nbsp&nbsp <vendor>ABC Ltd</vendor>
    &nbsp&nbsp&nbsp&nbsp <copyright>Copyright (c) 2004 ABC Ltd</copyright>
    &nbsp&nbsp&nbsp&nbsp <fileset Java="1.0">
    &nbsp&nbsp&nbsp&nbsp&nbsp <directory></directory>
    &nbsp&nbsp&nbsp&nbsp&nbsp <files>MyTestAppLib.cod</files>
    &nbsp&nbsp&nbsp&nbsp </fileset>
    &nbsp&nbsp&nbsp&nbsp </application>
    &nbsp&nbsp </application>
    </loader>

    The .alx file, along with the .cod files, is needed if installation is done via cable.

    Like most manufacturers, RIM provides its own set of libraries. To name a few, they are encryption components, push capability with the use of the BES (BlackBerry Enterprise Server), and enhanced GUI widgets. You should consult their user guides and the Java doc for more information. The main question here is whether you can mix the two. In short, the answer is no; once you start using the core framework provided by RIM, you cannot mix it with the regular J2ME libraries. However, I did find it possible to use pure MIDP/CLDC libraries and call certain packages specific to RIM, such as sound and vibration. You will have to do some experimenting here yourself. The second question related to this topic is portability, of course. If you decide to use the rich RIM libraries, you may find it increasingly more difficult to port your application to another handset.

    Challenges and Considerations

    Some of the challenges and considerations when developing for BlackBerry devices are:

    1. Display-This is nothing new to those of you already developing with J2ME. Screen size varies from model to model. Also, the older models are black and white and the new models are in color.
    Form Factor-This is definitely a big factor. You must consider the way in which a user interacts with a BlackBerry. The main input devices are the track-wheel and the side escape key. You application must utilize and should conform to how the OEM application uses these devices so, from a user’s point of view, he/she doesn’t have to adjust to your application. For games, there are no arrow keys or soft keys; instead, there is a full keyboard for the user to use. You’ll need to do some testing to determine which keys will best suit the user.

    2. Target Audience-In general, most BlackBerry users are business-oriented people, so you may want to give some thought as to what type of game/application you will develop for the BlackBerry. Obviously, market research is needed in this area.

    3. Different OS-In some instances, I’ve found different OS versions on the same model produced different graphic outputs, such as fonts. This makes sense considering the Font library uses what is available in the system. So, that is something to take into consideration as well.

    4. Different networks-This may or may not have an effect on your application, but beware of network protocols such as CDMA, GPRS, and iDEN.

    Hints and Tips

    1. Obfuscation-The JDE doesn’t seem to directly support obfuscation. You’ll need to obfuscate the application/game outside the JDE. Afterwards, create a new project and drop in the JAR file; this will then create the appropriate obfuscated .cod file.

    2. HTTP Connections-When simulating network calls, you need to turn on the MDS (Internet gateway server). You’ll notice that it’s nothing more then a customized Tomcat. However, do not try and run your server-side code on it; this it won’t work. You’ll need to run another instance of Tomcat or another server on another port other than 8080.

    3. Referring to the last point, if you decide to use the BES in production, your HTTP calls should be fine; however, if you decide not to, you will need to specify WAP Protocol information. Please consult the developer guide for more information. You will have to contact specific carriers if you want support to obtain the exact WAP information. Some carriers do list this information on their Web sites.

    4. Desktop Software-The end user may have problems installing your application via cable because the Desktop Software that came with their purchase is out of date. They will have to visit their carrier’s Web site for the latest download.

    Summary

    Well, I hope I tweaked your interest in developing for the BlackBerry. No, they aren’t paying me to promote them. I just think that the more devices your application/game can support, the more opportunity there is for you to hit a wider user base and, if you’re in it for money, the more revenue opportunities.

    References/Support

    I suggest you go and register for free at the developer section at RIM. The support team there is great, and the turnaround time is usually less then 24 hours.

    http://www.rim.com

    http://www.blackberry.com/developers/na/index.shtml

    http://resources.rimdev.com/Default.htm

    Jason is a wireless and open source developer enthusiast who enjoys creating synergy and sharing knowledge in the software development world. To learn more about him visit his personal site at http://www.jasonlam604.com/

    Related Articles

    LEAVE A REPLY

    Please enter your comment!
    Please enter your name here

    Latest Articles