Author: Ian Darwin --
Published? true --
Android is "the open source revolution" applied to cellular telephony.
At least, part of it.
There are many other attempts to provide open source cell phones,
ranging from the mostly-defunct Openmoko Freerunner through QT Embedded, Moblin, LiMo, Debian Mobile, Maemo to the
recently-open-sourced Symbian OS.
Not to mention the established non-open-source stalwarts:
Blackberry OS, Apple's iPhone, and Microsoft Windows Mobile
(these have developer toolkits, but their OS is not
available as open source).
"Nobody's armchair is a good predictor of the future", though,
as Mike O'Dell once said. Does Android have a place in the sun alongside these other players? We think it does. This book is here to help the Android developer community share the knowledge that will make it happen. Those who contribute knowledge here are helping make Android development easier for those who come after.
Android is a mobile technology platform
that provides cell phones and other hand-held and mobile devices (even netbooks)
with the power and portability of the Linux operating system
and the reliability and portability of a standard high-level language and API.
Android apps are written in the Java language, using tools such as Eclipse,
compiled against the Android API, and translated into bytecode for the Dalvik VM.
Android is thus related by OS family to Openmoko, QT Embedded,
MeeGo (the 2010 merger of Nokia's Maemo and Intel's MobLin),
OPhone, LiMo and other Linux-based cell phone projects.
Android is also related by programming language to Blackberry and JavaME phones,
and to Java and the wider realm of Java Enterprise applications.
Android sales have continued to climb; there is a report from NPD that
first-quarter 2010 sales of all Android devices exceeded sales of the iPhone, moving it into second place
(although still well behind the Blackberry platform).
Surely it was due in part to major carrier Verizon's 2-for-1 sale,
but that doesn't account for all of it...
Who This Book Is For
We assume you know the basics of the Java language. If not, see Learning Java. We also assume you know the basics of the Java Standard Edition API (since this forms the basis of Android's runtime libraries) as well as the basics of Android. The terms "activity", "intent", and "content provider", while not necessarily being what you dream about at night, should at least be familiar to you.
What's in this Book?
Chapter 1, Getting Started, takes you through the steps of setting up the Android development environment and building several simple applications of the well-known "Hello World" type pioneered by Brian Kernighan.
Chapter 2, Designing a successful Application, covers some of the differences in mobile computing that will hit developers coming from desktop and enterprise software environments, and talks about how mobile design (in particular Android design) differs from those other environments.
Testing is often an afterthought for some developers, so we put this early on, in Chapter 3, Testing. Not so you'll skip it, but so you'll read and heed. We talk about unit testing individual components as well as testing out your entire application in a well-controlled way.
In Chapter 4, Content Providers, we show you how to make an application that can be used by other applications through something as simple but ubiquitous (in Android) as the URL.
Every mobile app needs a GUI, so Chapter 5, Graphical User Interface, covers all the ins and outs of GUI development for Android. Examples are given both in XML and in hard-coded GUI development.
Chapter 6, Graphics, covers a range of topics related to graphics, including use of the graphical drawing and compositing facilities in Android as well as using desktop tools to develop graphical images, textures, icons, and so on that will be incorporated into your finished application.
Android is rich in multimedia capabilities. Chapter 7, Multimedia, shows how.
Chapter 8, Data Persistence shows how to save data into files, databases and so on. And how to retreive it later, of course.
Android started out as an operating system for mobile telephones. Chapter 9, Telephone Applications, shows how to control and react to the telephone device that is in most mobile devices nowadays.
Mobile devices are, for the most part, always-on and always-connected. This has a major impact on how people use them and think about them. Chapter 10, Networked Applications, shows the coding for traditional networked applications, and Chapter 11, Cloud Computing, considers massively-distributed applications.
The now-ubiquitous Global Positioning System has also had major implications on how mobile applications work. Chapter 12, Location and Map Applications, discusses how to find your location, how to get map data from Google and OpenStreetMap, and how applications can be location-aware in ways that are just now being explored.
Chapter 13, Accelerometer, talks about the sensors built into most Android devices and how to use them.
There may be a Chapter 14, Bluetooth, if there's enough to say about it, going way beyond connecting your Bluetooth(TM) headset to your phone.
In Chapter 15, Other Programming Languages, we explore the use of other programming languages to write all or part of your Android application. Examples include C, Perl, Python, Lisp, and other languages.
While this book is in English, and English remains the #1 language worldwide, it is far from the only one. And most end users would much rather have an application that has its text in their language and its icons in a form that is culturally correct for them. Chapter 16, Internationalization, goes over the issues of language and culture and how it relates to Android.
Most Android developers hope that their applications will be used by other people. But this won't happen unless users can find your application. Chapter 17, Packaging, deploying and selling, shows how to prepare your application for distribution via the Android Market, and to use that as well as other markets to get your application out to the people that will use it.
Programming and Design Books
Conventions Used in This Book
This book uses the following conventions.
The examples shown are in two varieties. Those that begin with zero or more import statements, a Javadoc comment, and a public class statement are complete examples. Those that begin with a declaration or executable statement, of course, are excerpts. However, the full versions of these excerpts have been compiled and run, and the online source for that recipe should include the full versions.
The following typographic conventions are used in this book:
Used for commands, filenames, and example URLs. It is also used to define new terms when they first appear in the text.
Used in code examples to show partial or complete Java source code program listings. It is also used for class names, method names, variable names, and other fragments of Java code.
Constant width bold
Used for user input, such as commands that you type on the command line.
This icon signifies a tip, suggestion, or general note.
This icon indicates a warning or caution.
Comments and Questions
As mentioned earlier, we rely on each contributor to test all the code on at least one of the Android versions, and hopefully on several. Still, there may be hidden dependencies, or even bugs, in the code. Please report any errors you find, as well as your suggestions for future editions. If you have (or create) an account on the online site, you can attach the comment directly to the Recipe, using the Add Comment feature. You can also reach us by writing to:
O'Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
(800) 998-9938 (in the United States or Canada)
(707) 829-0515 (international or local)
(707) 829-0104 (fax)
To ask technical questions or comment on the book, send email to:
firstname.lastname@example.org. An O'Reilly web site for the book lists errata, examples, and any additional information. You can access this page at:
http://www.oreilly.com/catalog/XXX PUT ISBN NUMBER HERE/.
The online website for the book will remain available at
http://androidcookbook.oreilly.com/. We hope it will grow and grow as developers continue to add recipes beyond those in the printed edition of the book.
Getting the Source Code
Unlike most O'Reilly books, there is no central repository of source code. Each developer can choose to make source available electronically, or not. There is a spot for each contributor to list a source download link (and also a binary .apk link). These are presented in text, as hyperlinks, and formatted as QRCodes, the square bar-codes you will see at the end of some recipes.