INTRODUCTION

Now is an exciting time for mobile developers. Mobile phones have never been more popular, and powerful smartphones are now a popular choice for consumers. Stylish and versatile phones packing hardware features like GPS, accelerometers, and touch screens, combined with fixed-rate, reasonably priced data plans provide an enticing platform upon which to create innovative mobile applications.

A host of Android handsets are now available to tempt consumers, including phones with QVGA screens and powerful WVGA devices like the Motorola Droid and the Google Nexus One. The real win though, is for developers. With much existing mobile development built on proprietary operating systems that restrict the development and deployment of third-party applications, Android offers an open alternative. Without artificial barriers, Android developers are free to write applications that take full advantage of increasingly powerful mobile hardware and distribute them in an open market.

As a result, developer interest in Android devices has exploded as handset sales have continued to grow. In 2009 and the early parts of 2010 more than 20 Android handsets have been released from OEMs including HTC, Motorola, LG, Samsung, and Sony Ericsson. Android devices are now available in over 26 countries on more than 32 carriers. In the United States, Android devices are available on all four major carriers: T-Mobile, Verizon, AT&T, and Sprint. Additionally, you can now buy the unlocked Google Nexus One handset directly from Google at http://www.google.com/phone.

Built on an open source framework, and featuring powerful SDK libraries and an open philosophy, Android has opened mobile phone development to thousands of developers who haven't had access to tools for building mobile applications. Experienced mobile developers can now expand into the Android platform, leveraging the unique features to enhance existing products or create innovative new ones.

Using the Android Market for distribution, developers can take advantage of an open marketplace, with no review process, for distributing free and paid apps to all compatible Android devices.

This book is a hands-on guide to building mobile applications using version 2 of the Android software development kit. Chapter by chapter, it takes you through a series of sample projects, each introducing new features and techniques to get the most out of Android. It covers all the basic functionality as well as exploring the advanced features through concise and useful examples.

Google's philosophy is to release early and iterate often. Since Android's first full release in October 2008, there have been seven platform and SDK releases. With such a rapid release cycle, there are likely to be regular changes and improvements to the software and development libraries. While the Android engineering team has worked hard to ensure backwards compatibility, future releases are likely to date some of the information provided in this book.

Nonetheless, the explanations and examples included here will give you the grounding and knowledge needed to write compelling mobile applications using the current SDK, along with the flexibility to quickly adapt to future enhancements.

WHOM THIS BOOK IS FOR

This book is for anyone interested in creating applications for the Android mobile phone platform using the SDK. It includes information that will be valuable, whether you're an experienced mobile developer or you're making your first foray, via Android, into writing mobile applications.

It will help if readers have used mobile phones (particularly phones running Android), but it's not necessary, nor is prior experience in mobile phone development. It's expected that you'll have some experience in software development and be familiar with basic development practices. While knowledge of Java is helpful, it's not a necessity.

Chapters 1 and 2 introduce mobile development and contain instructions to get you started in Android. Beyond that, there's no requirement to read the chapters in order, although a good understanding of the core components described in Chapters 3 through 7 is important before you venture into the remaining chapters. Chapters 8 through 15 cover a variety of optional and advanced functionality and can be read in whatever order interest or need dictates.

WHAT THIS BOOK COVERS

Chapter 1 introduces Android, including what it is and how it fits into existing mobile development. What Android offers as a development platform and why it's an exciting opportunity for creating mobile phone applications are then examined in greater detail.

Chapter 2 covers some best practices for mobile development and explains how to download the Android SDK and start developing applications. It also introduces the Android developer tools and demonstrates how to create new applications from scratch.

Chapters 3 through 7 take an in-depth look at the fundamental Android application components. Starting with examining the pieces that make up an Android application and its life cycle, you'll quickly move on to the application manifest and external resources before learning about Activities, their lifetimes, and their life cycles.

You'll then learn how to create user interfaces with layouts and Views, before being introduced to the Intent mechanism used to perform actions and send messages between application components. Internet resources are then covered before a detailed look at data storage, retrieval, and sharing. You'll start with the preference-saving mechanism before moving on to file handling and databases. This section finishes with a look at sharing application data using Content Providers.

Chapters 8 to 14 look at more advanced topics. Starting with maps and location-based services, you'll move on to Services, background Threads, and using Notifications.

Next you'll learn how your applications can interact with the user directly from the home screen using widgets, live folders, Live Wallpaper, and the quick search box. After looking at playing and recording multimedia, and using the camera, you'll be introduced to Android's communication abilities.

The telephony API will be examined as well as the APIs used to send and receive SMS messages before going on to Bluetooth and network management (both Wi-Fi and mobile data connections).

Chapter 14 examines the sensor APIs, demonstrating how to use the compass, accelerometers, and other hardware sensors to let your application react to its environment.

Chapter 15 includes several advanced development topics, among them security, IPC, advanced graphics techniques, and user-hardware interactions.

HOW THIS BOOK IS STRUCTURED

This book is structured in a logical sequence to help readers of different development backgrounds learn how to write advanced Android applications.

There's no requirement to read each chapter sequentially, but several of the sample projects are developed over the course of several chapters, adding new functionality and other enhancements at each stage.

Experienced mobile developers with a working Android development environment can skim the first two chapters — which are an introduction to mobile development and instructions for creating your development environment — and dive in at Chapters 3 to 7. These cover the fundamentals of Android development, so it's important to have a solid understanding of the concepts they describe. With this covered, you can move on to the remaining chapters, which look at maps, location-based services, background applications, and more advanced topics such as hardware interaction and networking.

WHAT YOU NEED TO USE THIS BOOK

To use the code samples in this book, you will need to create an Android development environment by downloading the Android SDK, developer tools, and the Java development kit. You may also wish to download and install Eclipse and the Android Developer Tool plug-in to ease your development, but neither is a requirement.

Android development is supported in Windows, MacOS, and Linux, with the SDK available from the Android web site.

You do not need an Android device to use this book or develop Android applications.

Note

Chapter 2 outlines these requirements in more detail as well as describing where to download and how to install each component.

CONVENTIONS

To help you get the most from the text and keep track of what's happening, I've used various conventions throughout the book.

Note

Notes, tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.

As for styles in the text:

  • I show URLs and code within the text like so: persistence.properties.

  • To help readability, class names in text are often represented using a regular font but capitalized like so:

    Content Provider

  • I present code in two different ways:

    I use a monofont type with no highlighting for most code examples.

    I use bold highlighting to emphasize code that's particularly important in the present context.

  • In some code samples, you'll see lines marked as follows:

    [ ... previous code goes here ... ]

    or

    [ ... implement something here ... ]

    This represents an instruction to replace the entire line (including the square brackets) with actual code, either from a previous code snippet in the former case, or your own implementation in the latter.

  • To keep the code sample reasonably concise, I have not always included every import statement required in the code samples. The downloadable code samples described below include all the required import statements.

SOURCE CODE

As you work through the examples in this book, you may choose either to type in all the code manually or to use the source code files that accompany the book. All the source code used in this book is available for download at www.wrox.com. Once at the site, simply locate the book's title (either by using the Search box or by using one of the title lists), and click the Download Code link on the book's detail page to obtain all the source code for the book.

Note

Because many books have similar titles, you may find it easiest to search by ISBN; this book's ISBN is 978-0-470-56552-0.

Once you download the code, just decompress it with your favorite decompression tool. Alternatively, you can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

ERRATA

We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or faulty piece of code, we would be very grateful for your feedback. By sending in errata you may save another reader hours of frustration, and at the same time you will be helping us provide even higher quality information.

To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the book details page, click the Book Errata link. On this page, you can view all errata that have been submitted for this book and posted by Wrox editors. A complete book list including links to each book's errata is also available at www.wrox.com/misc-pages/booklist.shtml.

If you don't spot "your" error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml and complete the form there to send us the error you have found. We'll check the information and, if appropriate, post a message to the book's Errata page and fix the problem in subsequent editions of the book.

P2P.WROX.COM

For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.

At http://p2p.wrox.com, you will find a number of different forums that will help you not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:

  1. Go to p2p.wrox.com and click the Register link.

  2. Read the terms of use and click Agree.

  3. Complete the required information to join as well as any optional information you wish to provide, and click Submit.

  4. You will receive an e-mail with information describing how to verify your account and complete the joining process.

Note

You can read messages in the forums without joining P2P, but in order to post your own messages, you must join.

Once you join, you can post new messages and respond to messages other users post. You can read messages at any time on the Web. If you would like to have new messages from a particular forum e-mailed to you, click the "Subscribe to This Forum" icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

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

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