INTRODUCTION

I FIRST STARTED PLAYING WITH THE ANDROID SDK before it was officially released as a 1.0 release. Back then, the tools were unpolished, the APIs in the SDK were unstable, and the documentation was sparse. Fast forward two and a half years, Android is now a formidable mobile operating system, with a following no less impressive that the iPhone. Having gone through all the growing pains of Android, I think now is the best time to start learning about Android programming — the APIs have stabilized and the tools have improved. But one thing remains: Getting started is still an elusive goal for many. What’s more, Google has recently released their latest version of the Android SDK — 3.0, for tablet development. The Android 3.0 SDK comes with several new features for tablet developers, and understanding all these new features requires some effort on the part of beginners. It was with this mission in mind that I was motivated to write a book that beginning Android tablet programmers could appreciate, and one that would enable them to write progressively sophisticated applications.

This book was written to help jump-start beginning Android developers, in particular developers targeting tablet devices. It covers just enough for you to get started with tablet programming using Android. You will learn the basics of the new features in Android 3.0. For a more comprehensive overview of the various programming capabilities of Android, I suggest you look at my other book, Beginning Android Application Development (Wrox, 2011).

To make the learning interesting, this book walks through the process of building two projects. The first project shows how to build a mapping application for your Android tablet. You will be able to monitor your current location using the built-in GPS, cellular, and wireless network connections. In addition, you will be able to view your location using the Google Maps. The second project demonstrates how to build a pair of location tracker applications, allowing you to track the geographical locations of other Android users through the use of SMS messaging. These two projects serve as a solid starting point for building real-life tablet applications. Have fun!

WHO THIS BOOK IS FOR

This book is for the beginning Android tablet developer who wants to start developing tablet applications using the Google’s Android 3.0 SDK. To truly benefit from this book, you should have some background in programming and at least be familiar with object-oriented programming concepts. If you are totally new to Java — the language used for Android development — you might want to take a programming course in Java programming first, or grab one of many good books on Java programming. In my experience, if you already know C# or VB.NET, learning Java is not too much of an effort; you should be comfortable just following along with the Try It Out exercises.

For those totally new to programming, I know the lure of developing mobile apps and making some money is simply too tempting to miss. However, I think a better starting point is learning the basics of programming before attempting to try out the examples in this book.

image

NOTE All the examples discussed in this book were written and tested using version 2.x and 3.0 of the Android SDK. While every effort has been made to ensure that all the tools used in this book are the latest, it is likely that by the time you read this, a newer version of the tools may be available. As such, some of the instructions/screenshots may differ slightly. However, any changes should be minimal and you should not have any problems following along.

WHAT THIS BOOK COVERS

This book covers the fundamentals of Android programming using the Android SDK. It is divided into six chapters and three appendices.

Chapter 1: Getting Started with Android Programming for Tablets covers the basics of the Android OS and its current state. You will learn about the features of Android devices, as well as some of the popular devices on the market. You will then learn how to download all the required tools to develop Android applications and then test them on the various types of Android emulators.

Chapter 2: Components of an Android Tablet Application covers the various parts that make up an Android tablet application and some of the new features in Android 3.0 that are specifically designed for tablet applications. In particular, you will learn about the fragment and Action Bar APIs new in Android 3.0, and how you can make use of them to develop compelling tablet applications.

Chapter 3: Android User Interface covers the various components that make up the UI of an Android application. You will learn about the different layouts you can use to build the UI of your application, and the numerous events that are associated with the UI when users interact with the application. You will also learn about the specialized fragments available for Android tablet applications.

Chapter 4: Creating Location-Based Services Applications shows how to make use of Google Maps in your Android application, and how to manipulate it programmatically. In addition, you will learn how to obtain your geographical location using the LocationManager class available in the Android SDK. By the end of the chapter, you will have created a very cool Android tablet mapping project.

Chapter 5: SMS Messaging and Networking demonstrates how to send and receive SMS messages programmatically from within your Android application. You will also learn how to use the HTTP protocol to talk to web servers so that you can download text and binary data. The last part of this chapter shows you how to parse XML files to extract the relevant parts of an XML file — a technique that is useful if you are accessing Web services. By the end of this chapter, you will have built a functional location tracker application!

Chapter 6: Publishing Android Applications discusses the various ways you can publish your Android applications when you are ready. You will also learn about the steps to publishing and selling your applications on the Android Market.

Appendix A: Using Eclipse for Android Development provides a quick run-through of the many features in Eclipse.

Appendix B: Using the Android Emulator provides tips and tricks on using the Android emulator to test your applications.

Appendix C: Answers to Exercises contains the solutions to the end-of-chapter exercises found in every chapter.

HOW THIS BOOK IS STRUCTURED

This book breaks down the task of learning Android programming into several smaller chunks, enabling you to digest each topic before delving into a more advanced one.

If you are a total beginner to Android programming, start with Chapter 1. Once you are comfortable with the basics here, head on to the appendices to read more about Eclipse and the Android emulator. When you are ready, you can continue with Chapter 2 and gradually move into more advanced concepts.

A key feature of this book is that all the code samples in each chapter are independent of those discussed in previous chapters. This gives you the flexibility to dive into the topics that interest you most and start working on the Try It Out projects.

WHAT YOU NEED TO USE THIS BOOK

All the examples in this book run on the Android emulator (which is included with the Android SDK). However, to get the most out of this book, having a real Android device would be optimal (though not absolutely necessary).

CONVENTIONS

To help you get the most from the text and keep track of what’s happening, we’ve used a number of conventions throughout the book.

TRY IT OUT: These Are Exercises or Examples for You to Follow

The Try It Out exercises appear once or more per chapter as exercises to work through as you follow the text in the book.

1. They usually consist of a set of numbered steps.

2. Follow the steps through with your copy of the project files.

How It Works

After each Try It Out, the code you’ve typed is explained in detail.

As for other conventions in the text:

  • New terms and important words are highlighted in italics when first introduced.
  • Keyboard combinations are treated like this: Control+R.
  • Filenames, URLs, and code within the text are treated like so: persistence.properties.

Code is presented in two different ways:

We use a monofont type with no highlighting for most code examples.
We use bold to emphasize code that is of particular importance in the present context.
image

WARNING Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.

image

NOTE Notes, tips, hints, tricks, and asides to the current discussion look like this.

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. When at the site, simply locate the book’s title (use the Search box or 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.

image

NOTE Because many books have similar titles, you may find it easiest to search by ISBN; this book’s ISBN is 978-1-118-10673-0.

Code that is included on the website is highlighted by the following CodeNote:

code snippet filename

After you download the code, just decompress it with your favorite compression tool. Alternatively, 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, such as a spelling mistake or a 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 help 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 has been submitted for this book and posted by Wrox editors.

image

NOTE 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 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 want 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.

image

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

After you join, you can post new messages and respond to messages that other users post. You can read messages at any time on the Web. If you want 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 for 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