Anybody can start building simple apps for the Android platform, and this book will show you how! Android Apps for Absolute Beginners takes you through the process of getting your first Android applications up and running using plain English and practical examples. It cuts through the fog of jargon and mystery that surrounds Android application development, and gives you simple, step-by-step instructions to get you started. Teaches Android application development in language anyone can understand, giving you the best possible start in Android development Provides simple, step-by-step examples that make learning easy, allowing you to pick up the concepts without fuss Offers clear code descriptions and layout so that you can get your apps running as soon as possible What you’ll learn Get yourself and your computer set up for Android apps development Use the Eclipse programming environment to make your Android development efficient and straightforward Follow steps in plain English to build simple apps and get them working immediately Style your application so that it appeals to potential users Make use of the Android’s touch screen Use shortcuts and cheat sheets to create apps the easy way Use the basics of Java and XML to move onto more advanced apps Who this book is for If you have a great idea for an Android app, but have never programmed before, then this book is for you. You don’t need to have any previous computer programming skills—as long as you have a desire to learn, and you know which end of the mouse is which, the world of Android apps development awaits! Table of Contents Preliminary Information: Before We Get Started What’s Next? Our Road Ahead Setting Up an Open Source Android Development Environment An Introduction to Java, XML and How Android Works An Overview of the Android Application Framework Screen Layout Design: Views, ViewGroups and Layout Types User Interface Design: Buttons, Menus, Dialogs and Alerts Designing Graphics for Android: 2D Images & Animation Adding Interactivity: Handling UI Events Understanding Content Providers Understanding Intents and Intent Filters The Future: 3D, Widgets, Bluetooth, Maps, Search, and More Cover......Page 1 Contents at a Glance......Page 3 Contents......Page 333 About the Author......Page 338 About the Technical Reviewer......Page 339 Acknowledgments......Page 340 The Weapon: Android, the Innovative Mobile Code Environment......Page 4 The Formula for Success......Page 5 Operating System and IDE......Page 6 Dual Monitors......Page 7 Preliminary Information: Before We Get Started......Page 8 Some History: What Is Android?......Page 9 Advantage Android: How Can Android Benefit Me?......Page 10 What’s Covered......Page 11 Preparing for Liftoff: SDK Tools to Download......Page 12 Java......Page 13 Eclipse......Page 14 Summary......Page 15 Your Android Development IDE......Page 17 Java, XML, and How Android Works......Page 19 Screen Layout Design......Page 20 Graphics and Animation Design......Page 21 Content Providers......Page 22 The Future of Android......Page 23 Summary......Page 24 Installing Java, Eclipse, and Android......Page 25 Java SE and JRE: Your Foundation for Application Development......Page 26 Eclipse IDE: The Development Environment......Page 27 Android SDK: The Android Tool Kit for Eclipse......Page 31 Android Development Tool: Android Tools for Eclipse......Page 32 The Android Environment Within Eclipse......Page 36 Updating the Android SDK......Page 37 AVDs: Smartphone Emulators......Page 39 USB Smartphone Drivers: External Devices......Page 41 Developing on 64-Bit Computing Platforms......Page 42 Summary......Page 44 Introducing the Android Software Development Platform......Page 46 Understanding Java SE and the Dalvik Virtual Machine......Page 47 The Directory Structure of an Android Project......Page 48 Common Default Resources Folders......Page 49 The Values Folder......Page 50 Leveraging Android XML (Your Secret Weapon)......Page 51 Desktop Clocks......Page 52 Bitmap Images......Page 53 Alternate Resource Folders......Page 54 Launching Your Application: The AndroidManifest.xml File......Page 55 Launching Eclipse......Page 56 Creating an Android Project......Page 57 Inspecting and Editing the Application Files......Page 60 Setting a Variable Value in strings.xml......Page 64 Running the App......Page 65 Adding an Application Icon......Page 66 Summary......Page 70 Android Framework Overview......Page 72 The Foundation of OOP: The Object......Page 73 Some OOP Terminology......Page 74 The Blueprint for an Object: The Class......Page 75 Providing Structure for Your Classes: Inheritance......Page 80 Defining an Interface......Page 81 Bundling Classes in a Logical Way: The Package......Page 82 An Overview of XML......Page 83 The Anatomy of an Android Application: The APK File......Page 84 Android Application Components......Page 85 Android Activities: Defining the UI......Page 86 Broadcast Receivers: Announcements and Notifications......Page 87 Content Providers: Data Management......Page 88 Android Intent Objects: Messaging for Components......Page 89 Android Manifest XML: Declaring Your Components......Page 90 Summary......Page 92 Android View Hierarchies......Page 94 Nesting Views: Using the ViewGroup Class......Page 95 Setting Up for Your Screen Layout......Page 97 Using Linear Layouts......Page 98 Using Relative Layouts......Page 109 Sliding Drawers: Expanding Your UI......Page 113 Using Padding and Margins with Views and Layouts......Page 116 Summary......Page 117 Using Common UI Elements......Page 119 Adding an Image Button to Your Layout......Page 120 Adding a Text to Your Layout......Page 130 Adding an Image......Page 131 Using Menus in Android......Page 133 Creating the Menu Structure with XML......Page 134 Defining Menu Item Strings......Page 135 Inflating the Menu Structure via Java......Page 138 Making the Menu Work......Page 140 Displaying an Alert Dialog......Page 144 Summary......Page 149 An Introduction to Graphics Resources in Android......Page 150 Implementing Images......Page 151 Using Bitmap Images in Android......Page 152 PNG Images......Page 153 Frame-based or Cel 2D Animation......Page 154 Tween Animation in Android......Page 163 Using Transitions......Page 169 Creating 9-Patch Custom Scalable Images......Page 173 Adding a VideoView Object......Page 179 Adding the Java for Video......Page 181 Summary......Page 184 Listening for and Handling Events......Page 185 Event Callback Methods......Page 186 Handling onClick Events......Page 187 Implementing an onClick Listener for a UI Element......Page 188 Adding an onClick Listener to an Activity in Android......Page 189 Touchscreen’s Right-Click Equivalent: onLongClick......Page 197 Keyboard Event Listeners: onKeyUp and onKeyDown......Page 200 Adding the Java for Keyboard Events......Page 201 Adding the XML for Context Menus......Page 204 Adding the Java for Context Menus......Page 206 Controlling the Focus in Android......Page 211 Adding the XML for Focus Control......Page 212 Adding the Java for Focus Control......Page 216 Summary......Page 218 An Overview of Android Content Providers......Page 219 Databases and Database Management Systems......Page 220 Android Built-in Content Providers......Page 221 Defining a Content Provider......Page 224 Creating the Content Providers Example Project in Eclipse......Page 225 Defining Security Permissions......Page 226 Adding Data to the Contacts Database......Page 230 Querying a Content Provider: Accessing the Content......Page 233 Appending to a Content Provider: Adding New Content......Page 239 Modifying Content Provider Data: Updating the Content......Page 245 Removing Content Provider Data: Deleting Content......Page 250 Summary......Page 255 What Is an Intent?......Page 257 Android Intent Messaging via Intent Objects......Page 258 Explicit Intents......Page 261 Implicit Intents......Page 262 Using Intents with Activities......Page 263 Writing the Digital Clock Activity......Page 268 Wiring up the Application......Page 271 Sending Intents......Page 273 Using Intents with Services......Page 276 Creating a Service......Page 279 Implementing Our MediaPlayer Functions......Page 283 Wiring the Buttons to the Service......Page 284 Running the Application......Page 285 Using Intents with Broadcast Receivers......Page 286 Creating the Timer User Interface via XML......Page 287 Creating a Timer Broadcast Receiver......Page 288 Configuring the AndroidManifest.xml file Tag......Page 290 Implementing our Intent......Page 291 Running the Timer Application via the Android 1.5 Emulator......Page 296 Summary......Page 297 Widgets: Creating Your Own Widgets in Android......Page 298 Location-Based Services in Android......Page 300 Google Maps in Android......Page 301 Google Search in Android......Page 304 Shared Preferences......Page 305 External Memory......Page 306 Device Administration: Security for IT Deployments......Page 307 3D Graphics: Using OpenGL ES 1.x in Android......Page 308 SoundPool......Page 309 MediaRecorder......Page 310 Summary......Page 311 A......Page 312 C......Page 315 E......Page 317 G......Page 318 I......Page 319 L......Page 321 M......Page 322 O......Page 323 R......Page 325 S......Page 326 T......Page 327 V......Page 328 Z......Page 329 Anybody can start building simple apps for the Android platform, and this book will show you how! Recently updated to include Android Jelly Bean, Android Apps for Absolute Beginners, Second Edition takes you through the process of getting your first Android apps up and running using plain English and practical examples. This book cuts through the fog of jargon and mystery that surrounds Android apps development, and gives you simple, step-by-step instructions to get you started. Teaches Android application development in language anyone can understand, giving you the best possible start in Android development Provides simple, step-by-step examples that make learning easy, allowing you to pick up the concepts without fuss Offers clear code descriptions and layout so that you can get your apps running as soon as possible This book is Android Jelly Bean compliant, but is backwards compatible to most of the previous Android releases.