About this Book

Android in Action, Second Edition is a revision and update of Unlocking Android, published in April 2009. This book doesn’t fit nicely into the camp of “introductory text,” nor is it a highly detailed reference manual. The text has something to offer both the beginner and the experienced developer who is looking to sell his or her application in the Android Market. This book covers important beginner topics such as “What is Android” and installing and using the development environment. We then advance to practical working examples of core programming topics any developer will be happy to have at the ready on the reference shelf. The remaining chapters present very detailed example applications covering advanced topics, including a complete field service application, localization, and material on Android web applications, Bluetooth, sensors, AppWidgets, and integration adapters. We even include two chapters on writing applications in C—one for the native side of Android and one using the more generally accepted method of employing the Android Native Development Kit.

Although you can read the book from start to finish, you can also consider it a couple of books in one. If you’re new to Android, focus first on chapter 1, appendix A, and then chapter 2. With that foundation, you can then work your way through chapters 3 through 12. Chapter 13 and on are more in-depth in nature and can be read independently of the others.

The audience

We wrote this book for professional programmers and hobbyists alike. Many of the concepts can be absorbed without specific Java language knowledge, though the most value will be found by readers with Java programming skills because Android application programming requires them. A reader with C, C++, or C# programming knowledge will be able to follow the examples.

Prior Eclipse experience is helpful, but not required. A number of good resources are available on Java and Eclipse to augment the content of this book.

Roadmap

This book is divided into four parts. Part 1 contains introductory material about the platform and development environment. Part 2 takes a close look at the fundamental skills required for building Android applications. Part 3 presents a larger scope application and a Native C Android application. Part 4 explores features added to the Android platform, providing examples of leveraging the capable Android platform to create innovative mobile applicatoins.

Part 1: The Essentials

Part 1 introduces the Android platform, including its architecture and setting up the development environment.

Chapter 1 delves into the background and positioning of the Android platform, including comparisons to other popular platforms such as BlackBerry, iPhone, and Windows Mobile. After an introduction to the platform, the balance of the first chapter introduces the high-level architecture of Android applications and the operating system environment.

Chapter 2 takes you on a step-by-step development exercise, teaching you the ropes of using the Android development environment, including the key tools and concepts for building an application. If you’ve never used Eclipse or have never written an Android application, this chapter will prepare you for the next part of the book.

Part 2: The Programming Environment

Part 2 includes an extensive survey of fundamental programming topics in the Android environment.

Chapter 3 covers the fundamental Android UI components, including View and Layout. We also review the Activity in more detail. These are the basic building blocks of screens and applications on the Android platform. Along the way, we also touch on other basic concepts such as handling external resources, dealing with events, and the lifecycle of an Android application.

Chapter 4 expands on the concepts you learned in chapter 3. We delve into the Android Intent to demonstrate interaction between screens, activities, and entire applications. We also introduce and use the Service, which brings background processes into the fold.

Chapter 5 incorporates methods and strategies for storing and retrieving data locally. The chapter examines use of the filesystem, databases, the SD card, and Android-specific entities such as the SharedPreferences and ContentProvider classes. At this point, we begin combining fundamental concepts with more real-world details, such as handling application state, using a database for persistent storage, and working with SQLite.

Chapter 6 deals with storing and retrieving data over the network. Here we include a networking primer before delving into using raw networking concepts such as sockets on Android. From there, we progress to using HTTP, and even exploring web services (such as REST and SOAP).

Chapter 7 covers telephony on the Android platform. We touch on basics such as originating and receiving phone calls, as well as more involved topics such as working with SMS. We also cover telephony properties and helper classes.

Chapter 8 looks at how to work with notifications and alarms. In this chapter, we look at how to notify users of various events such as receiving a SMS message, as well as how to manage and set alarms.

Chapter 9 deals with the basics of Android’s Graphics API and more advanced concepts such as working with the OpenGL ES library for creating sophisticated 2D and 3D graphics. We also touch on animation.

Chapter 10 looks at Android’s support for multimedia; we cover both playing multimedia as well as using the camera and microphone to record your own multimedia files.

Chapter 11 introduces location-based services as we look at an example that combines many of the concepts from the earlier parts of the book in a mapping application. You’ll learn about using the mapping APIs on Android, including different location providers and properties that are available, how to build and manipulate map-related screens, and how to work with location-related concepts within the emulator.

Part 3: Bringing it all Together

Part 3 contains two chapters, both of which build on knowledge you gained earlier in the text, with a focus on bringing a larger application to fruition.

Chapter 12 demonstrates an end-to-end field service application. The application includes server communications, persistent storage, multiple Activity navigation menus, and signature capture.

Chapter 13 explores the world of native C language applications. The Android SDK is limited to the Java language, although native applications can be written for Android. This chapter walks you through examples of building C language applications for Android, including the use of built-in libraries and TCP socket communications as a Java application connects to your C application. This chapter is useful for developers targeting solutions beyond carrier-subsidized, locked down cell phones.

Part 4: The Maturing Platform

Part 4 contains six new chapters, each of which represents a more advanced development topic.

Chapter 14 demonstrates the use of both Bluetooth communication and processing sensor data. The sample application accompanying the chapter, SenseBot, permits the user to drive a LEGO Mindstorms robot with their Android phone.

Chapter 15 explores the Android contact database and demonstrates integrating with an external data source. In particular, this application brings Android into the social networking scene by integrating with the popular LinkedIn professional networking service.

Chapter 16 explores the world of web development. Android’s browser is based on the open source WebKit engine and brings desktop-like capability to this mobile browser. This chapter equips you to bring attractive and capable web applications to Android.

Chapter 17 brings the “home screen” of your Android application to life by showing you how to build an application that presents its user interface as an AppWidget. In addition to AppWidgets, this chapter demonstrates BroadcastReceiver, Service, and Alarms.

Chapter 18 takes a real-world look at localizing an existing application. Chapter 12’s Field Service application is modified to support multiple languages. Chapter 18’s version of the Field Service application contains support for both English and Spanish.

Chapter 19 reaches into Android’s open source foundation by using a popular edge detection image processing algorithm. The Sobel Edge Detection algorithm is written in C and compiled into a native library. The sample application snaps a picture with the Android camera and then uses this C algorithm to find the edges in the photo.

The Appendices

The appendices contain additional information that didn’t fit with the flow of the main text. Appendix A is a step-by-step guide to installing the development environment. This appendix, along with chapter 2, provides all the information you need to build an Android application. Appendix B demonstrates how to prepare and submit an application for the Android Market—an important topic for anyone looking to sell an application commercially.

Code conventions and downloads

All source code in the book is in a fixed-width font like this, which sets it off from the surrounding text. For most listings, the code is annotated to point out the key concepts, and numbered bullets are sometimes used in the text to provide additional information about the code. We have tried to format the code so that it fits within the available page space in the book by adding line breaks and using indentation carefully. Sometimes, however, very long lines will include line-continuation markers.

Source code for all the working examples is available from www.manning.com/AndroidinActionSecondEdition or http://www.manning.com/ableson2. A readme.txt file is provided in the root folder and also in each chapter folder; the files provide details on how to install and run the code. Code examples appear throughout this book. Longer listings will appear under clear listing headers while shorter listings will appear between lines of text.

Software requirements

Developing applications for Android may be done from the Windows XP/Vista/7 environment, a Mac OS X (Intel only) environment or a Linux environment. Appendix A includes a detailed description of setting up the Eclipse environment along with the Android Developer Tools plug-in for Eclipse.

A note about the graphics

Many of the original graphics from the first edition, Unlocking Android, have been reused in this version of the book. While the title of the revised edition was changed to Android in Action, Second Edition during development, we kept the original book title in our graphics and sample applications.

Author Online

Purchase of Android in Action, Second Edition includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the authors and from other users. To access the forum and subscribe to it, point your web browser to www.manning.com/AndroidinActionSecondEdition or www.manning.com/ableson2. This page provides information on how to get on the forum once you’re registered, what kind of help is available, and the rules of conduct on the forum.

Manning’s commitment to our readers is to provide a venue where a meaningful dialog between individual readers and between readers and the authors can take place. It’s not a commitment to any specific amount of participation on the part of the authors, whose contribution to the AO remains voluntary (and unpaid). We suggest you try asking the authors some challenging questions lest their interest stray!

The Author Online forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.

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

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