Chapter 1

Setting the Stage

There has never been a better time to develop applications for BlackBerry devices than right now. Since Research In Motion (RIM) launched the first models almost a decade ago, the BlackBerry smartphone has gone from relative obscurity to near universal visibility—think about how commonplace it has become to see people in airports, hotels, offices, or just about anywhere stealing a few minutes to check their e-mail or type replies. The BlackBerry software development kit (SDK) has been around since the first devices were released and has grown to include an extensive collection of examples and documentation, and a mature set of APIs and tools that have opened the door for all kinds of great applications, most of which only currently exist in someone’s imagination. And with the maturing of the BlackBerry community and the introduction of BlackBerry App World, it’s easier than ever to get your application noticed and downloaded by users worldwide.

In this chapter we’ll talk a bit about the basics of BlackBerry development: development environment options (there are a couple), other software and information you need, and some things to keep in mind. We’ll also walk through the download and setup of the development tools and simulators so you’re all set up to start building applications in the next chapter.

What This Book Is

This book is a guide to help you get started creating your own BlackBerry applications. This book is not about writing web applications for BlackBerry devices or about rapid application development (RAD) solutions, such as MDS Studio or the BlackBerry plug-in for Microsoft Visual Studio. This is about building professional, polished, native applications that take full advantage of the BlackBerry platform.

By the end of this book, you’ll have built several simple BlackBerry applications, learned how to run them on the various BlackBerry simulators, and learned how to package and deploy them onto real BlackBerry devices. You’ll learn how a BlackBerry application is put together, how to create great-looking user interfaces, how to interact with the user (using the keyboard and trackball/trackpad or touch screen, depending on the device), how to send and receive data over the wireless network, and more. Combined with the extensive development resources and examples provided by RIM, you’ll be on your way to creating the next killer application for this platform.

What You Need to Know Before You Can Begin

To be able to follow along, you should have previous programming experience in a modern object-oriented language. This book is not an introduction to object-oriented programming or even to the Java language. There are many excellent resources and tutorials available on the Internet.

BlackBerry applications are written in Java Micro Edition (Java ME), formerly called J2ME. This is a subset of Java Standard Edition (Java SE) that most Java developers work with. If you’re familiar with Java SE or Java Enterprise Edition (Java EE), Java ME will be very easy to pick up.

If you’re familiar with another object-oriented language—especially one with a similar syntax, such as C#, C++, or even Objective-C—you should similarly have no problem picking things up. C# developers in particular should be able to understand Java ME code with little or no effort.

One of the nice things about Java ME and the BlackBerry from the perspective of a beginner is that the API is small compared to desktop or server programming environments—you can learn a great deal of it fairly quickly. Of course, this is a double-edged sword; there will be times when you wish the API provided some functionality that bigger environments do, though the BlackBerry API is getting more functionality all the time.

Setting Up Your Development Environment

Before you can begin writing applications for BlackBerry you’ll need a few things. First, you’ll need a computer running Windows 2000 SP1 or later, Windows XP, Windows Vista, or Windows 7. Any desktop or laptop produced in the last few years should be sufficient, but as with any software development, the more RAM and CPU speed you have, the better your experience will be. Because you will be running an integrated development environment (IDE) of your choice (you have two options) and the simulator where you test your application, we recommend at least 4GB of RAM and a dual-core processor so you will be able to compile and run your BlackBerry application swiftly.

The first stop for all BlackBerry development tools and other resources is the BlackBerry Developer Zone, at www.blackberry.com/developers/ (see Figure 1–1). Here, you’ll find free downloads, whitepapers, the developer knowledge base, and the BlackBerry Developer Forums. As a BlackBerry developer, you should get to know this site very well.

images

Figure 1–1. The BlackBerry Developer Zone

In addition, in order to download any tools from RIM, you have to log in with a BlackBerry developer account. So take this time and sign up for yourself.

RIM does offer higher-level paid Independent Software Vendor (ISV) programs with additional support and other benefits, but you can develop and distribute applications with the free account. We recommend this to enterprise developers who have support Service Level Agreement (SLA) with clients, because if there is a support issue around a certain BlackBerry API, your ISV technical representative will then be able to answer your inquiries and/or provide workarounds for your problem. For more information, see http://partners.blackberry.com/.

Installing the Development Environment

There are two BlackBerry development environments produced by RIM: the BlackBerry Java Development Environment (JDE) and the BlackBerry JDE Plug-in for Eclipse. Both are very functional and have been used by developers to produce professional applications. The JDE has been around longer and is a bit more mature, but almost everything possible with the JDE can also be accomplished with the Eclipse plug-in. The Eclipse plug-in leverages the entire Eclipse development platform, which includes a world-class source code editor and a lot of third-party plug-ins. Ultimately, the choice is a matter of personal preference. Although we have used JDE since the very beginning days of BlackBerry development and it has come a long way, the developer-friendly features of Eclipse IDE with the new updates to the BlackBerry JDE Plug-in for Eclipse make the latter a natural choice for BlackBerry development. For the rest of this book, we’ll be focused on using the Eclipse plug-in.

Before you start development for BlackBerry, you will need to first decide what BlackBerry operating system (OS) version your application will support, which then will determine what Eclipse JDE plug-in component pack you will need to build your application. Each version of the component pack for the Eclipse plug-in corresponds to a major version of the BlackBerry OS. BlackBerry does a good job of keeping its OS backward compatible, so something developed for OS 5.0 generally will work the same on OS 6.0 and higher. However, you may want to use some features that are only available on a later OS. A safe minimum is 5.0, which covers majority of the BlackBerry devices on the market and is supported by BlackBerry App World.

Before installing the BlackBerry development tools, you’ll need to install the Java SE JDK from www.oracle.com/technetwork/java/index.html. For most developers, downloading Java SE JDK v6.0 is a good choice—it will let you develop for BlackBerry Device Software version 4.5 and later, which covers majority of BlackBerry smartphones on the market. More specific information is available in the Developer Zone at http://na.blackberry.com/eng/developers/javaappdev/javadevenv.jsp.

Installing the BlackBerry Java Plug-In for Eclipse

To use Eclipse to develop for BlackBerry, you’ll need to download Eclipse IDE. However, to make things simple for you, RIM has bundled Eclipse 3.6 (Helios) with the BlackBerry JDE Plug-in with BlackBerry SDK 7.0, which is shown in Figure 1–2. You can download the BlackBerry Java Plug-in for Eclipse at http://us.blackberry.com/developers/javaappdev/devtools.jsp.

images

Figure 1–2. Eclipse with the BlackBerry JDE plug-in

Setup is simply a matter of running the setup executable file.

Using Other JDE Versions with Eclipse

Other JDE versions are supported within the same environment with downloadable component packs. You can install other component packs for Eclipse from within Eclipse itself. Open Eclipse IDE and do the following:

  1. Select Help Menu.
  2. From the menu, select the Install New Software menu item. The Install New Software screen will appear.
  3. From the Install New Software screen, click the Add button.
  4. Paste http://www.blackberry.com/go/eclipseUpdate/3.6/java into the location text box, give it the name “text box,” and click OK (see Figure 1–3).
  5. Select the BlackBerry Java Plug-in item and at least one BlackBerry Component Pack item that you want to work (see Figure 1–4).
  6. Then follow the onscreen instruction to finish installation. You will have to restart Eclipse IDE in order for the installation to take effect.
images

Figure 1–3. The Eclipse Install New Software screen, where you specify the location of the BlackBerry update site

images

Figure 1–4. Select the BlackBerry component pack you want to install.

Downloading Additional Simulators

In addition to the simulators that are available to you in the BlackBerry Java Plug-in for Eclipse, RIM provides many simulators that are very useful for testing how your application functions with different screen resolutions or input methods. The simulators can be downloaded from the Developer Zone, at http://na.blackberry.com/eng/developers/resources/simulators.jsp (see Figure 1–5 for a sample list).

images

Figure 1–5. The Simulators download page showing some of the many choices

Installing Desktop Software

If you want to load your application onto a BlackBerry device directly from your computer (i.e., without having to upload to a web server and download to your device over the wireless connection), you’ll need to install the BlackBerry Desktop Manager (see Figure 1–6), which includes the device drivers for the BlackBerry. You may already have this installed, since it comes on a CD with your device. Alternatively, you can download it from www.blackberry.com. You’ll also need this to be able to debug your application on a device using your USB cable.

images

Figure 1–6. You can use the BlackBerry Desktop Manager to load applications from your computer to your device.

Getting Code Signing Keys

For basic applications, you can compile and run on real BlackBerry devices with no further involvement from RIM using the free tools. However, if you want to use certain features (such as the BlackBerry persistent store, cryptography APIs, and embeddable web browser), or if you want to allow your application to do things like automatically start, you’ll need code signing keys from RIM. The code signing keys are only required to use controlled APIs from an application running on a device; you can run an application on the simulator that uses controlled APIs without having to sign it.

Since the free code signing keys usually only take a day or two to receive, it’s a good idea to get them while you’re setting up your development environment—almost every BlackBerry application ends up needing to use at least a few controlled APIs.

You can find more information and register for the code signing keys at http://na.blackberry.com/eng/developers/javaappdev/codekeys.jsp.

The online application form for signing keys is available at https://www.blackberry.com/SignedKeys/.

When filling in the key request form, remember the PIN you choose. You’ll need it to install the keys into your JDE. Because it’s sometimes a point of confusion, it’s worth pointing out that your signing key PIN is not related to a BlackBerry device PIN in any way.

Installing Your Code Signing Keys

Once you’ve applied for your signing keys, you should receive three e-mails from RIM, each containing one of the code signing keys. Each gives access to a different part of the API, and you should install all three on the same PC. Follow the steps in this section for each of the three keys.

To install your code signing keys in Eclipse with the BlackBerry JDE plug-in, simply import the keys by doing the following:

  1. From Eclipse IDE, select Windows from the menu, and then choose Open Perspective images Others.
  2. Select the BlackBerry Application Development perspective.

    NOTE: If you do not use the BlackBerry Application development perspective, you will not see the BlackBerry menu in the next step

  3. Then from the menu, select BlackBerry images Sign images Install New Key.

You’ll be prompted to create a new public/private key pair (see Figure 1–7).

images

Figure 1–7. When installing your first key, you’ll be prompted to create a new key pair.

Click Yes on this dialog, and you’ll be asked for a private key password to protect your key file. Remember this password—you’ll be asked for it every time you want to sign your application. You’ll then be asked to generate some random data by moving your mouse pointer around (see Figure 1–8). A word of warning: This will seem like more fun than it should.

images

Figure 1–8. Generating random information for your new key pair—whee!

After this, you’ll be asked to enter the PIN you provided when you applied for your keys and the private key password you just entered (see Figure 1–9). Do this and your key will be installed and ready to use.

images

Figure 1–9. Registering a code signing key with the JDE

For the next two keys, you’ll already have generated your key pair, so you’ll just have to enter the PIN and private key password.

Once you’ve created your key pair and installed your three keys, the key information is stored in three files:

sigtool.csk
sigtool.db
sigtool.set

The location of these files is <eclipse_directory>plugins et.rim.ejdevmTools, where <eclipse_directory> is where you installed your Eclipse environment (i.e., C:Eclipseplugins et.rim.ejdevmTools).

It’s also a very good idea to keep a backup of these files and your original key files if you ever have to rebuild your development environment.

What’s Different About Developing for BlackBerry

If you’re familiar with developing for modern desktop PCs or servers, there are many things you might not think about before starting to develop for BlackBerry. Of course, every platform is different, but there are some things to keep in mind when designing and implementing an application for BlackBerry.

Limited CPU and Memory

Generally, BlackBerry CPU speed and RAM—as with most mobile devices—lag a few years behind average PCs. The latest BlackBerry devices are getting faster, so this isn’t as much of a constraint as it was a few years ago. There are lots of reasons for these limitations, including prolonging battery life and keeping devices small, but in general, it’s good to keep in mind that your processor-intensive desktop application algorithm may not run as nicely on a BlackBerry device. Ways around this include redesigning your application to let the server, if you have one, do some of the heavy lifting.

Also, because the BlackBerry OS is multitasking, CPU- or RAM-hungry applications running in the background can make things difficult for other applications on the device. This is another way of saying, “Play nice with other applications on the device!”

Java As the Native API

The Java virtual machine (VM) on the BlackBerry is as close to the hardware as you can get. You can’t write a non-Java native application for the platform. This means that you’re always in a garbage-collected, bytecode-interpreted environment, and you don’t have real-time access to the hardware.

Limited Screen Real Estate

The largest BlackBerry device screen, in terms of number of pixels and physical size, is the touch-screen Storm. It measures 3.7 inches and has a 480×800-pixel resolution. Most devices have a 3-inch or smaller screen.

User Input

The BlackBerry Storm lets the user click anywhere on the screen. Other devices don’t have a touch screen, so the user is limited to the trackball (or trackpad on some recent device models) and keyboard. The trackball is like a set of up, down, left, and right cursor keys—not like a mouse. Your user interface must be designed with this in mind. Imagine how difficult it would be to navigate around a modern Windows application (like Microsoft Office) using just your cursor keys, and you’ll have an idea of what the BlackBerry constraints mean.

Many Different Devices

A range of BlackBerry devices is currently being sold and used, and their screen resolutions range from 240×260 to 480×360. Physical screen sizes change too.

Some of the devices have a trackball or optical trackpad along with a keyboard, but a couple of models have a touch screen instead. Some have full QWERTY keyboards, while others have the BlackBerry SureType keyboard, which has one or two letters per key. The BlackBerry Storm can present different types of virtual keyboards depending on device orientation and user preferences.

Processor speed and RAM vary from device to device, as does network speed. And some hardware features, such as GPS, are not available on all devices.

You should be aware of these differences and design your application to work with as many devices as possible if you want to reach a significant number of BlackBerry users.

What’s in This Book

Here’s a brief overview of the remaining chapters in this book.

Chapter 2

In this chapter, you’ll learn how to build a simple BlackBerry application using the BlackBerry JDE and the JDE Plug-in for Eclipse. We’ll debug the application using the simulator and on a real device.

Chapter 3

This chapter will discuss a number of concepts and topics important to BlackBerry applications in general, laying down some groundwork to help you understand the rest of the chapters.

Chapter 4

In this chapter, you’ll start to explore the user interface API in depth by building an application that supports multiple screens and a variety of different user interface controls.

Chapter 5

We’ll modify the application from Chapter 4 by creating and extending a number of user interface components, and you’ll learn how to work with the user interface model and create a custom look and feel for your applications.

Chapter 6

Next, we’ll move beyond the user interface. You’ll learn how to persistently store data on the device between invocations of the application or resets of the device. We’ll also explore the BlackBerry file system.

Chapter 7

This chapter will explore wireless networking by creating an application that interacts with a web service on the Internet.

Chapter 8

In Chapter 8, we’ll explore the location-based services support on the BlackBerry platform by creating an application that gets location information using the GPS hardware on a BlackBerry smartphone and interacts with BlackBerry maps to display location information.

Chapter 9

In this chapter we’ll discuss how to package and distribute your application, both from your own website and through other means. We’ll talk in depth about BlackBerry App World and how to leverage its features, and then briefly discuss some third-party application stores.

Chapter 10

Chapter 10 will provide a few final bits of information and a list of BlackBerry development resources that you can use to help answer your future questions.

Summary

In this chapter, we skimmed the surface and covered what you need to start with BlackBerry development.

We started out by listing the different development environments you can setup to write BlackBerry code (we recommend using BlackBerry Java Plug-in for Eclipse). We then covered where to get more simulator for testing your application, as well as how to request code signatures that are required to sign your application before you can load your app onto a BlackBerry device.

Finally, we ended this chapter by summarizing rest of the chapters in this book. Let’s get started!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset