Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 514 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
514
Dung lượng
10,6 MB
Nội dung
COMPANION eBOOK
Shelve in
Mobile Computing
User level:
Intermediate–Advanced
www.apress.com
BOOKS FOR PROFESSIONALS BY PROFESSIONALS
®
SOURCE CODE ONLINE
A
dvanced BlackBerry6Development gives you a comprehensive look at the
new features included with SDK 6, including the new Web browser, advanced
UI fields and layout managers, and the new push services API. You’ll get an intro-
duction to cross-platform libraries that run on the latest BlackBerry devices and
other smartphone platforms, including OpenGL ES, OpenVG, barcode scanning,
and SQLite. You’ll also learn how to take advantage of BlackBerry media capabili-
ties like the camera and video playback. The book also shows you how to send
and receive text and multimedia messages, use powerful cryptography libraries,
and connect with the user’s personal and business contacts and calendar.
Not only will you learn how to use these APIs, but you’ll also build an app that
takes full advantage of them. You will apply each chapter’s lessons by enhancing
the app from a prototype to a fully polished program. Along the way, you’ll learn
how to differentiate your product from other apps by fully integrating with the
new BlackBerry6 operating system. Your app will run in the browser and within
device menus, just like software that comes with the phone.
Once you are comfortable with writing apps, this book will show you how to
take them to the next level. You’ll learn how to move from running on one
phone to running on all phones, and from one country to all countries. You’ll
additionally learn how to support your users with updates. No other resource
compares for mastering the techniques needed for expert development on this
mobile platform.
Advanced
BlackBerry 6
Development
Chris King
Unlock the secrets of advanced
BlackBerry 6 development
King
Companion
eBook
Available
BlackBerry 6 Development
Advanced
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
Download from Wow! eBook <www.wowebook.com>
iv
Contents at a Glance
■Contents v
■About the Author xiv
■About the Technical Reviewer xv
■Acknowledgments xvi
■Introduction xvii
Part I: Advanced APIs 1
■Chapter 1: Getting Started 3
■Chapter 2: Media Capture 39
■Chapter 3: Media Playback 69
■Chapter 4: Wireless Messaging 111
■Chapter 5: Cryptography 157
Part II: Device Integration 187
■Chapter 6: Personal Information 189
■Chapter 7: Browser with Web Apps 233
■Chapter 8: Integrating with the BlackBerry OS 263
Part III: Going Pro 299
■Chapter 9: RIM Security 301
■Chapter 10: Porting Your App 327
■Chapter 11: Advanced Build Techniques 359
Part IV: The New Frontier 377
■Chapter 12: Push Services 379
■Chapter 13: BlackBerry6 UI 401
■Chapter 14: Cross-Platform Libraries 433
■Appendix: Codec Support 457
■Index 465
■ INTRODUCTION
xvii
Introduction
Carrying a BlackBerry used to speak volumes about a person. When you saw someone tapping at
that wide keyboard with both thumbs, you could safely assume that the owner was a
businessperson, and that the person’s time was so valuable that he or she couldn’t afford to be
out of touch from the office for even a moment. Today, you can no longer make that assumption.
BlackBerry 6 and other recent releases have played up the devices’ power, connectivity, and
media capabilities. Now these devices are carried by teenagers, surfers, knitters—seemingly
everyone. Anyone who has experienced that large screen, that expansive keyboard, and that
powerful processor will not contentedly return to a crammed phone with a multi-tap dial pad.
The explosion in the number of BlackBerry devices has raised people’s expectations, and also
created a tempting marketplace for programmers everywhere. BlackBerry6 applications offer a
rich and expressive interface for a mobile device, and people will pay for the best apps available.
Developers sell their applications on BlackBerry App World, through off-deck stores like
Handango, and through wireless carrier stores. Many more people program for fun and load their
applications on their own devices or those of friends. And, because BlackBerry still has
dominated the enterprise marketplace, many programmers write applications particularly for
their internal business customers.
This book will show you how to make the most of your BlackBerry applications. It focuses on
the most fun, the most impressive, and the most rewarding aspects of development. By the time
you finish, you should be able to write professional-quality applications that run on the latest
devices.
The Book’s Anatomy
Advanced BlackBerry6Development is divided into four parts. Each part concentrates on a
particular theme. The book was designed to be read in sequence, as each chapter builds on the
chapters that come before, but veteran developers can easily move to the parts that interest them
the most.
Part 1, “Advanced APIs”
This first part of the book focuses on the rich feature set offered by BlackBerry6 devices. By
examining individual topics, you can gain a great depth of knowledge about the material.
■
Chapter 1, “Getting Started”: Provides a quick introduction to BlackBerry
development. You’ll see how to set up your programming environment and learn the
fundamentals of Java development for BlackBerry.
■ INTRODUCTION
xviii
■ Chapter 2, “Media Capture”: Shows how to record audio, photos, and video from
within your application or other applications on the device.
■ Chapter 3, “Media Playback”: Describes the vast range of media types supported by
BlackBerry 6 and how to include each one within an application.
■ Chapter 4, “Wireless Messaging”: Introduces the technologies used to send and
receive various types of messages including SMS, e-mail, and BlackBerry PIN.
■ Chapter 5, “Cryptography”: Offers a quick primer on security, including how to
obscure information, determine authenticity, and prevent tampering. Discusses the
various toolkits available for cryptography, their advantages, and how to use each.
Part 2, “Device Integration”
This part of the book turns toward leveraging existing functions on the device. Canny
programmers will take advantage of the resources built into each BlackBerry, and learn how to
make their app indispensible to the user.
■ Chapter 6, “Personal Information”: Examines the various repositories of personal
data on the phone, such as the address book and calendar. Shows how to read,
update, and create new records from within your application.
■ Chapter 7, “Browser with Web Apps”: Explores the trade-offs between web app,
widget, and application development. Describes the various types of browsers and
how they impact your development. Covers browser APIs for embedding browsers
within apps or apps within browsers.
■ Chapter 8, “Integrating with the BlackBerry OS”: Covers several useful techniques
such as providing customized icons, communicating between applications, and
adding options to the device’s native menus.
Part 3, “Going Pro”
While the first two parts of the book primarily focus on adding features to your applications, this
part focuses on technique: how to improve your software in ways that may not be visible to the
user, but that make it more robust and improve your efficiency.
■ Chapter 9, “RIM Security”: Deciphers the occasionally baffling security model that
constrains the behavior of BlackBerry applications. This chapter explains the critical
issues that may come up as you develop your application or that emerge only after it
has been released. In the process, you’ll learn what tools are available to get the
permissions you need, and how to deal with cases where your app is forbidden from
doing certain things.
■ Chapter 10, “Porting Your App”: Provides an overview of the many issues to face
when you make your application available for multiple devices or multiple countries.
By learning these lessons early, you can make the inevitable porting process much
quicker and more enjoyable.
■
Chapter 11, “Advanced Build Techniques”: Shows how to move from a one-person
operation to a more professional and organized approach. Introduces the many tools
available for use, including build scripts, debug logging, release packages, and more.
■ INTRODUCTION
xix
Part 4, “The New Frontier”
This final part describes the latest additions to the BlackBerry6 OS, which will help differentiate
your app and provide maximum impact.
■ Chapter 12, “Push Services”: Explains how to hook your client application into an
end-to-end push solution, which can dramatically transform the user experience and
improve efficiency. Use the latest APIs to significantly ease push app development.
■ Chapter 13, “BlackBerry 6 UI”: Covers the latest and most complex additions to the
BlackBerry UI toolkit, including building complex tables, crafting arbitrary layouts
based on absolute coordinates, using native pickers, and displaying standardized
progress indicators.
■ Chapter 14, “Cross-Platform Libraries”: Provides an introduction to several popular
open source libraries that RIM has recently added to the OS, including OpenGL ES for
3D graphics, OpenVG for accelerated 2D graphics, SQLite for relational databases,
and ZXing for barcode scanning.
What’s Changed?
If you have previously read AdvancedBlackBerry Development, you’ll find that the content has
been updated throughout the book to reflect the latest capabilities and the best current practices.
I have also removed material that has grown obsolete. Some areas, like personal information,
have remained very similar, while others, like the browser, have drastically changed. The final
part of the book contains three all-new chapters covering push services, advanced UI topics, and
a variety of cross-platform libraries.
Keep in mind that BlackBerry devices are backward-compatible, so any app you wrote for
previous versions of the OS should continue to work properly on OS 6. However, the latest
devices have the newest and most compelling features, so over time you may want to upgrade
those old apps to use BlackBerry6 APIs. You may want to review the chapters covering features
used by your apps to see what has changed and whether any of the new features appeal to you.
How to Read This Book
Depending on your background and goals, you might approach this book in different ways. The
chapters are designed to be read in order, as later chapters may reference content from earlier
chapters. However, such references are made explicit in the text, and you might find it more
useful to approach the book in another order according to your interests or most pressing
deadlines.
Novice
If you are new to BlackBerry development, you should start with Chapter 1, which offers an
accelerated introduction to the platform. Spend as much time here as you need, and continue
once you are comfortable with all the material. You can continue reading the remainder of the
book in sequence, working through all the examples and reading the notes.
■ INTRODUCTION
xx
Apprentice
If you have previously written basic BlackBerry apps, you can skim Chapter 1, reading any
unfamiliar topics. From here, you can proceed through the book in sequence, focusing on the
chapters that offer new material.
Journeyman
Veteran Java ME developers will notice that many of the BlackBerry APIs, particularly those
related to media, personal information, and wireless messaging, are similar or identical to their
Java ME counterparts. I point out the important differences within the text. These developers
should particularly focus on Chapter 1 for setting up their BlackBerry environment and Chapter 9
to learn about the critical differences between Java ME and BlackBerry security.
Master
Finally, BlackBerry experts can largely skip Chapter 1, and refer to individual chapters to learn
about particular topics of interest. Veterans will recognize the importance of BlackBerry device
software versions, and will pay particular attention to the tables that show the significant
differences between versions.
Notes on Conventions
One of my personal pet peeves is that most programming books today are written as if it were still
1990. Thanks to the ubiquitous availability of Javadocs, we can easily look up the details about
individual methods. Thanks to modern IDEs, we can easily discover available APIs and find out
how to use them properly.
In writing this book, I’ve focused on the things that you can’t easily see in the Javadocs: the
meaning behind methods, when to call particular APIs, and the trade-offs between various
solutions. To avoid distraction, I generally omit parameters when I name a method. I generally
omit the package name when I name a class. In Eclipse, Ctrl+Space is your friend. Of course, in
situations where usage is ambiguous, I provide the details explaining which item to use.
Similarly, exception handling is a great tool for writing robust software, but tends to muddy
even the simplest examples. I generally omit exception handling when introducing a new method
unless its exceptions are particularly unusual.
The end of each chapter contains a longer set of sample code that runs as a stand-alone
application. Here, I fully handle all exceptions, include full package names, and do everything
else to show how a real-world application should look and perform.
Your Media App
Each chapter contains numerous small snippets of code designed to help illustrate particular
points. The end of each chapter shows how to create a useful, stand-alone application that
incorporates concepts from throughout the chapter. In order to provide the experience of writing
a realistic, feature-rich application, you will build a single media-sharing application throughout
the course of the book. Each chapter from Chapter 2 onward will contribute a new section to it,
gradually improving it from a skeleton of an app to a robust platform for media communication.
Complete source code for this media app is provided at the Apress web site, www.apress.com.
You can download the sample for each chapter, along with any other listings provided within the
main body of the chapter. I encourage you to use the source code as a reference, not an answer
key. You will learn the most by working through the sample yourself, adding sections gradually,
then running and observing the code. If you skip chapters while reading, you might want to
■ INTRODUCTION
xxi
download the previous chapter’s source code solution, and then make the modifications for the
current chapter on your own.
The Trailhead
I go hiking in the mountains almost every weekend. I love the sensations you get in a good hike.
You feel invigorated by the sense of mystery and possibility. As you climb higher and higher, the
ground drops away below you. You start to gain perspective, with your visual range extending to
yards and then miles. As you continue to ascend, you see even more of the landscape, but it isn’t
static: every curve brings an unexpected new sight, every switchback a fresh vista. No matter how
challenging a hike is, once you reach the summit, you feel that it’s all worthwhile, and feel a sense
of ownership as you survey the land below you.
I find that learning a new technology is a great deal like that sort of hike. When you start, you
can see only the things right in front of you: the editor, the syntax, the tools. As you continue to
progress, you begin to catch sight of the wide range of features that the technology offers. You
gain more and more mastery, and with that experience comes perspective, as you begin to see
how the technology’s pieces all work together. But as with a hike, you can always keep going a
little further, always learn something new. I’ve found BlackBerry programming to be a
particularly fun trail, and hope you will enjoy the journey too. Keep striving, keep moving
upward, and appreciate the view.
Part
Advanced APIs
The best BlackBerry apps take advantage of the rich set of advanced APIs available on
this platform. The chapters in Part 1 describe some of the most exciting and compelling
features available to you. Chapter 1 provides a crash course in building a variety of RIM
applications that can access the local filesystem and the Internet. From there, learn how
to use the device to shoot photos, record sound and video, and use the captured data in
your app. Next, see the wide variety of options available for playing video, animations,
and audio content. Connect the BlackBerry to the rest of the mobile world with wireless
messaging and email technologies. Finally, incorporate today’s techniques for
safeguarding data into your own applications.
I
3
3
Chapter
Getting Started
Welcome to the wonderful world of BlackBerry app development! Chapter 1 aims to get
you up to speed as quickly as possible, so you can get right into the good stuff, and it
assumes no previous knowledge other than a basic grasp of Java. This chapter will walk
you through downloading software and setting up your environment, and then it will give
you a quick tour through the basics of BlackBerry app development. You may linger,
skim, or skip ahead as your patience demands.
Initial Setup
As with any new language or platform, you will need to install some new software and
set up your computer appropriately. You have many different options for creating a
successful BlackBerry project. Research In Motion (RIM) historically supported only
Windows development, but it has done a good job of releasing tools that enable
development on a variety of configurations. The following section will focus on what I
have found to be the simplest and most effective setup for independent development,
with occasional notes for alternative choices you might consider.
Getting Java
You will develop in Java for the BlackBerry, but before we get that far, we need to make
sure Java on your desktop is running properly. RIM uses Java for its toolchain—the set
of programs that will convert your application source files into a format that can run on
the mobile device. Additionally, our Eclipse IDE requires a Java runtime environment.
To see if Java is installed, open a command prompt. You can do this by clicking Start
Run, typing cmd, and pressing enter. A black-and-white command prompt window will
appear. Type java -version. You should see something like the following:
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing)
1
[...]... your first BlackBerry app 1 Start Eclipse and select a fresh workspace 2 Click File 3 Expand BlackBerry and select BlackBerry Project Click Next Verify that the JRE matches your intended target, such as BlackBerry JRE 6. 0.0 Name the project “HelloWorld” If you hate the idea of writing another Hello World application, call it something else Click Finish 4 Expand the HelloWorld project, and open BlackBerry_ App_Descriptor.xml... like 6. 0.0.141” When selecting a component pack, only the first two numbers are important The rest will be used to select an appropriate simulator You should restart Eclipse once the install is complete After it restarts, you will see a new BlackBerry menu option in the Project menu You will also have access to three new debug configurations: BlackBerry Device, BlackBerry Simulator, and Running BlackBerry. .. download the plug-in installer directly from the BlackBerry developer web site This should allow you to use the plug-in, although it will require you to manually download and install any updates RIM releases in the future BlackBerry Programs If you are developing for a personal BlackBerry device, you probably already have the BlackBerry Desktop Software and the BlackBerry Device Manager installed If not,... going to your Start menu and looking under BlackBerry Depending on your installation choices, the manager may automatically start when you log in to Windows Figure 1–2 shows the BlackBerry Desktop Manager running Figure 1–2 BlackBerry Desktop Software 7 8 CHAPTER 1: Getting Started NOTE: BlackBerry Desktop Software is not specifically a tool for developers Every BlackBerry user can install it, and most... matches all parts of the version number For example, if your device has version 6. 0.0.141, use only 6. 0.0.141, not another version that starts with 6. 0.0 You can download simulator packs from the BlackBerry web site The exact location will change, so your best bet is to visit the Developers page and look around for the BlackBerry Smartphone Simulators You will see many, many choices Pick the one that... BlackBerry Plug-in, do the following: 1 Open Eclipse, click the Help menu, and then click Install New Software 2 Click Add Enter any name that you like, and for the location, enter http://www .blackberry. com/go/eclipseUpdate/3.5/java Click OK 3 Expand the BlackBerry Java Plug-in category You will see several options At a minimum, you will need to select the BlackBerry Java Plug-in and at least one BlackBerry. .. directions on how to adapt to MIDlets CHAPTER 1: Getting Started To keep the focus on the advanced topics of this book, I tend to use simple Screen classes that are informative but not flashy If you’d like to learn more about designing user interfaces for BlackBerry CLDC apps, please consult Beginning BlackBerry 6 Development, by Anthony Rizk (Apress, 2011) Libraries The last major type of application... all the tools you will need to write, debug, and install your own BlackBerry apps Application Types Early in your development cycle, you will face an important decision—what kind of application architecture you should use BlackBerry supports three very different types of programs, and each offers a unique set of advantages and style of development This section will provide a quick tour and critique of... Properties, clicking Advanced system settings,” checking that the Advanced tab is selected, and then clicking Environment Variables Make sure the PATH includes the location of your installed java.exe directory This will probably be something like c:\dev\java\jre1 .6. 0_14\bin Goldilocks and the Three IDEs Once upon a time, a developer was evaluating which IDE to use when writing BlackBerry apps First... Most of the content in that book also applies to writing MIDlets for BlackBerry devices (Disclaimer: I am the technical reviewer of that book.) CLDC Applications MIDlets provide a good bridge of compatibility between Java ME and BlackBerry devices On the other hand, RIM engineered BlackBerry CLDC from the ground up specifically for BlackBerry, and this framework provides the best integration with the . needed for expert development on this
mobile platform.
Advanced
BlackBerry 6
Development
Chris King
Unlock the secrets of advanced
BlackBerry 6 development
King
Companion
eBook
Available
BlackBerry. level:
Intermediate Advanced
www.apress.com
BOOKS FOR PROFESSIONALS BY PROFESSIONALS
®
SOURCE CODE ONLINE
A
dvanced BlackBerry 6 Development gives you