To BlackBerry

This article was originally published in VSJ, which is now part of Developer Fusion.
The BlackBerry wireless handheld is so ubiquitous that it has entered the language, and yet it’s a platform developers tend to overlook, possibly because it doesn’t have a desktop equivalent. However, if you have any interest in mobile development, ignoring the BlackBerry platform is simply crazy, especially as it’s surprisingly easy to get into.

First, a little about the basic BlackBerry architecture. While early BlackBerry models only supported email applications, later devices are full PDAs and offer applications such as address book, calendar, etc. Connection to the internet is via the cell phone hardware, and “push” email is still the most important component. Companies wanting to offer BlackBerry-based email have to install the BlackBerry Enterprise Server (BES), but individual users can also access email accounts provided by the cell phone provider’s email services. BES monitors the user’s local inbox and automatically forwards new messages to the BlackBerry, with the user being notified that a new item is available without them having to check for new messages. A polling mode is also supported for interactions such as POP3 and off-line email reading. The BES also provides a full TCP/IP connection – Mobile Data Service (MDS) – which provides everything necessary for creating new connected applications.

In many ways it is the BES/MDS server combination that makes BlackBerry development different from other mobile devices. There are three levels at which you can create BlackBerry applications, each of which involves a little more investment in time and infrastructure but in turn provides additional payback. The first is browser development which makes best use of the skills that you already have as a web developer. This approach is minimal effort and is a good way of getting existing web applications customised for the BlackBerry. It also serves as an easy introduction to some of the fundamental tools in the BlackBerry developer’s arsenal – specifically the device and MDS simulators.

The second approach is referred to as Rapid Application Development, but don’t be put off by this name as it is as powerful as it is rapid. Its main advantage is that it enables you to create applications that connect to web services without the need to move to full Java development. The web services can be implemented using either .NET or Java and the client applications can be built using either a standalone MDS Studio tool or a plug-in for Visual Studio. You can build user interfaces using a drag-and-drop designer which are then implemented by the MDS Runtime, which is installed on the device just like any other native JavaME application.

The final approach is to build a custom JavaME program using full Java Application Development. This is, of course, the most costly but it also gives you complete control over what happens. You can take advantage of all of the smartphone features – camera, GPS, phone – and other functionality such as Maps, Messaging, address book and so on. Developing in Java isn’t difficult; the environment and language are easy to learn and any skills you might have in the .NET arena are easy to translate, but of course there are new APIs to learn. The good news is that the three approaches really do act like a ladder that you can work your way up, building applications, deploying and enhancing them as your knowledge, skill and comfort with the system improve.

Browser development

To start on the first rung – what is different about the BlackBerry Browser? The first and important thing to say is that if you want it to be so, there is no difference. The BlackBerry Browser supports all of the usual web standards and you can simply treat it like any compliant browser. The key difference is the way that it can work with the BES/MDS servers to connect to the internet in a secure and efficient way. All TCP/IP communication can be routed through the server to the wider internet and your web server in particular, in such a way as to make best use of the lower capacity channel a cell phone offers. For example, the BES applies encryption and compression without you having to request or implement it. It also applies some resource adjustments such as changing the resolution of images to suit the device display capabilities. At this point you might be worried by the idea of tying your application into the BES/MDS server – after all, what it if it isn’t available? In this case the BlackBerry Browser can connect to the web by a number of alternative services such as standard WAP and WiFi when available. These can provide fall-back configurations for your application if the BES/MDS server isn’t available.

The browser supports the usual standards: HTML, X-HTML-MP, WML 1.3, RSS, Atom, DOM and JavaScript 1.5, including the XMLHttpRequest object which is needed to implement Ajax approaches to dynamic pages. The JavaScript object model is augmented to include a BlackBerry object which offers the network property so that you can test for the type of connection in use. Similarly the BlackBerryLocation object provides access to GPS location information which can be used, perhaps with the help of Ajax, to customise pages that depend on the user’s location. The biggest area of specific innovation however is the support of push technology. Using the MDS connection you can arrange to place an icon on the device’s Home screen that changes to notify the user of new content, or you can arrange to send the content to the message list. Alternatively you can simply store the new data in the cache ready for the user to see it when they next view your content.

Support for push delivery of content is also available using other connections types. What is interesting is that a push service can be created very simply. The web server simply makes HTTP Post requests to the MDS service with a list of destination devices that have been targeted to receive the pushed content. The MDS takes care of delivery even if the user’s device is currently out of wireless contact. On the device a browser listener on port 7874 waits and processes incoming messages as soon as they arrive. This is a remarkably simple way of delivering a stream of content to a user and it might be all that you require to implement your BlackBerry application.

So how do you get started?

Simulators

While developing for the Web Browser doesn’t really require any additional environments or languages over and above what you need for standard web development, it does present some particular problems. The biggest is how to test what you have implemented? Clearly setting up a test network of BlackBerry devices is one way but it is hardly cost-effective. Fortunately a range of very high quality device simulators is available and can be freely downloaded from the BlackBerry website. The simulator is also the best way of testing and proving applications developed using the RAD or full Java approach so it is worth downloading, installing and trying out. You can even select from a range of different devices so that you can check how your application looks and behaves given different user interfaces and capabilities.

Screenshot
The BlackBerry device simulator with the MDS simulator window in the background

The simulators work under Windows and are trivial to install and easy to configure. In most cases you can simply make use of them without additional configuration. Being able to simulate a device is just half of the story however because testing is still going to need suitable BES/MDS servers to provide the connection.

Again the solution is to make use of a simulator – the BlackBerry MDS and/or ESS Simulator. If you run the MDS simulator before loading a device simulator then any URL that you enter into the simulation’s browser will be served to the device as if via a real MDS. It is worth downloading the device and MDS simulators simply to discover what any existing web applications look like when viewed on a BlackBerry! Once you know what they look like you can then work on making them better and customising them for BlackBerry viewing.

Pushing BlackBerries

Once you have a simulated device capable of browsing your website you can start to use JavaScript and standard HTML to customise the user’s experience. Probably the most common next step is to implement a push service. The best way of finding out how to do this is to download the Pushing content to the BlackBerry Browser lab, which is available as a zip Blackberry Developer Labs.

Screenshot
The push example is well worth downloading and investigating

A .NET and a Java version are included within the zip. To complete the task you will need to know how to create and work with the HTTP classes. The basic scheme is that you have to use an HTTP connection to download from your usual web server the content of the push. Next you use a second HTTP connection to send the data to the MDS after constructing appropriate HTTP headers to determine how the push is treated. Basically your program has to act as a push intermediary between the web page and MDS. In most cases the code provided as part of the example will serve as a good basis for what you need in a real example.

The BlackBerry browser provides an easy way of customising existing applications, but with a little thought it might be all you need to create a targeted end user application for the full range of devices. It requires minimal effort but it is still very versatile and provides a good starting point for more ambitious implementations. At the very least you should download and try out the device and MDS simulators.

Next month we will take the next step and customise the user interface using a RAD approach.


Mike James has over 20 years of programming experience, both as a developer and lecturer, and has written numerous books on programming and IT-related subjects. His PhD is in computer science.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Brevity is the soul of wit” - Shakespeare