Developing Android on Android
Automate Your Device with Scripts and Tasks
by Mike Riley
Version: P1.0 (November 2013)
Copyright 2013 The Pragmatic Programmers, LLC. This book is licensed tothe individual who purchased it. We don't copy-protect itbecause that would limit your ability to use it for yourown purposes. Please don't break this trustyou can use this across all of your devices but please do not share this copywith other members of your team, with friends, or via file sharing services. Thanks.
Dave & Andy.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com.
This book is dedicated to my three favorite Ms: Marinette, Marielle, and Mitchell.
Table of Contents
Copyright 2013, The Pragmatic Bookshelf.
Acknowledgments
This is my second book for Pragmatic Bookshelf, and it has been a pleasure to once again work with my dedicated and insightful development editor, Jackie Carter. If you can follow along with the projects without any problem, you have Jackie to thank. Her editorial skills and professional project management were crucial in keeping the book flowing smoothly and on schedule.
I would also like to thank all the wonderful technical editors and beta reader participants who shared valuable feedback, caught typos and other errors, and generally offered excellent suggestions on improving the quality of the book. In particular, I would like to thank Mike Bengtson for his awesome ingenuity, Corey Butler for his progressive technical edge, Ed Burnette for his pragmatic expertise, John Cairns for his eagle-eye criticality, and Glen Ferrel for his proofreading expertise and infectious enthusiasm. I also want to give a big shout-out to Dr. James Withers and Simon Wood (two of the geniuses behind the awesome SwiftKey Android soft keyboard replacement program) for their eagle-eye analysis of the books content. And a special thank-you goes to Jan Debiec and Cristina Zamora for their vigilant review of the material, active participation in the beta, and unending encouragement for my work. I am so blessed and humbled to be surrounded by such technically minded people as gifted, kind, and supportive as you.
No amount of thanks can match the sacrifice my family made to give me the time to devote to another book. I promise to take a break from book writing for a while so I can make up for lost time with you.
Lastly, a big high-five to publishers Andy Hunt and Dave Thomas for once again entrusting me to deliver a book worthy of the Pragmatic Bookshelf imprint. Thank you for giving me such a wonderfully rewarding opportunity to do so.
Copyright 2013, The Pragmatic Bookshelf.
Introduction
In this book, were going on a journey of discovery. Were going to discover how amazing the Android OS is and how it is transforming the way people communicate. Were also going to learn how to leave our legacy desktop PCs behind, even for native Android application development needs.
The idea for this book was the result of a conversation I had with Pragmatic Bookshelf publisher Dave Thomas. He had just acquired a Galaxy S3 Android phone and wanted to know what kind of cool things he could do with it. Since I have been an Android user since the release of the first commercial Android phone, the G1, I had a few suggestions on where to start. As he became more enthusiastic about the broad possibilities of customization and personalization that the Android platform has to offer, a new book on the subject started to crystallize.
The objectives of this book are simple. You will learn about how to apply and codify your mobile automation needs in an Android program. Using both scripting and native application development approaches, we will build several programs that not only teach you how to quickly automate your mobile lifestyle but also give you the skills to extend these programs beyond their tutorial roots.
Why Android? Why Now?
The Android OS is several years old, and its design principles (a modern, true multitasking mobile OS with built-in memory, permissions management, and so on) have been the same since its inception. So why is this book relevant now compared to five years ago, when Android was first introduced?
Obviously, the platform has matured considerably in that time. It has also greatly benefited from its open source approach by fostering significantly faster innovation compared to closed, proprietary operating systems. Take a look at a first-generation iPhone compared to the iPhone 5. While the hardware has vastly improved, the primary user interface is nearly identical. Consider the differences between Android 1.0 running on a G1 phone and Android 4.2 running on a Nexus 4. The differences are striking. The user interface, hardware support, design aesthetics, and everything but the original design principles have rapidly evolved for the better. One benefit from this co-evolution of hardware and software is that you can do things on a modern Android device that was the stuff of fiction five years ago. To think that on your Android device you can now do computing on a scale that was the exclusive domain of desktop PCs for the last thirty years is awe-inspiring.
This evolutionary path is also manifested in Android application development tools. Once clunky and incomplete, the Android SDK and Eclipse plug-ins are finally capable of stable, team-based, test-driven development. While the user interface construction toolkit could still use more polish, every other aspect of the typical Android development and emulation on a desktop PC is polished and professional.
One of the most exciting aspects of Android programming, testing, and deployment is that its application development life cycle can now be done directly on the Android device. This is a big deal. When compared to other mobile operating systems that require an expensive PC outfitted with a decent processor and plenty of RAM to run the target emulator, the projects discussed in this book require only your Android device. When you code and run applications on the same device, it greatly accelerates the development process, just as it did during the desktop PC era.
Lets also not forget that, like a desktop computer, Androids home screen can be highly customized and extended via custom wallpapers, animations, icons, folder actions, transition animations, and much more. This degree of personalization allows you to make your Android device fit your aesthetic values, daily workflow, and communication and notification preferences, not the other way around. Third-party extensions and widgets also help push the envelope of what is possible, further contributing to Androids success and dominant market position.