You are previewing Unlocking Android: A Developer’s Guide.
O'Reilly logo
Unlocking Android: A Developer’s Guide

Book Description

Android is a free, open source, Java-based mobile platform developed by Google. Unlocking Android prepares the reader to embrace the Android mobile platform in easy-to-understand language and builds on this foundation with reusable Java code examples. It's ideal for corporate developers and hobbyists who have an interest, or a mandate, to deliver mobile software.

The book first covers the big picture so the reader can get comfortable with the Android approach to the mobile applications. Then the reader learns to apply Android by following the many practical examples. The book concludes with two deep and hands-on examples.

Unlocking Android addresses the Android application framework, its graphical capabilities and media support, data storage, communications capabilities, phone interactions, and notifications.

Unlocking Android covers Android SDK 1.x

Table of Contents

  1. Copyright
    1. Dedication
  2. Foreword
  3. Preface
  4. Acknowledgments
    1. Frank Ableson
    2. Charlie Collins
    3. Robi Sen
  5. About This Book
    1. The Audience
    2. Roadmap
      1. Part 1: The Essentials
      2. Part 2: The Programming Environment
      3. Part 3: Bringing it All Together
      4. The Appendices
    3. Code Conventions
    4. Software Requirements
    5. Author Online
  6. About the Cover Illustration
  7. 1. What is Android?—The Big Picture
    1. 1. Targeting Android
      1. 1.1. Introducing Android
        1. 1.1.1. The Android platform
        2. 1.1.2. In the market for an Android?
          1. Mobile Operators
          2. Android vs. The Feature Phones
          3. Android vs. The Smartphones
          4. Android Vs. Itself
        3. 1.1.3. Licensing Android
      2. 1.2. Stacking up Android
        1. 1.2.1. Probing Android’s foundation
          1. Building on the Linux Kernel
          2. Running in the Dalvik Virtual Machine
      3. 1.3. Booting Android development
        1. 1.3.1. Android’s good Intent-ions
        2. 1.3.2. Activating Android
          1. Activity
          2. Service
          3. Broadcastreceiver
          4. Content Provider
        3. 1.3.3. AndroidManifest.xml
        4. 1.3.4. Mapping applications to processes
      4. 1.4. An Android application
      5. 1.5. Summary
    2. 2. Development environment
      1. 2.1. The Android SDK
        1. 2.1.1. The application programming interface
        2. 2.1.2. Core Android packages
        3. 2.1.3. Optional packages
      2. 2.2. Fitting the pieces together
        1. 2.2.1. Java Perspective
        2. 2.2.2. DDMS Perspective
        3. 2.2.3. Command-Line tools
          1. Android Asset Packaging Tool
          2. Android Debug Bridge
      3. 2.3. Building an Android application in Eclipse
        1. 2.3.1. Android Project Wizard
        2. 2.3.2. Android sample application code
        3. 2.3.3. Building the application
      4. 2.4. The Android Emulator
        1. 2.4.1. Skins
        2. 2.4.2. Network speed
        3. 2.4.3. Emulator profiles
      5. 2.5. Debugging
      6. 2.6. Summary
  8. 2. Exercising the Android SDK
    1. 3. User interfaces
      1. 3.1. Creating the Activity
        1. 3.1.1. Creating an Activity class
        2. 3.1.2. Exploring Activity lifecycle
          1. Understanding How Processes and Activities Relate
          2. Activity Lifecycle
      2. 3.2. Working with views
        1. 3.2.1. Exploring common views
        2. 3.2.2. Using a ListView
        3. 3.2.3. Multitasking with Handler and Message
        4. 3.2.4. Creating custom views
        5. 3.2.5. Understanding layout
        6. 3.2.6. Handling focus
        7. 3.2.7. Grasping events
      3. 3.3. Using resources
        1. 3.3.1. Supported resource types
        2. 3.3.2. Referencing resources in Java
        3. 3.3.3. Defining views and layouts through XML resources
        4. 3.3.4. Externalizing values
        5. 3.3.5. Providing animations
      4. 3.4. Understanding the AndroidManifest file
      5. 3.5. Summary
    2. 4. Intents and services
      1. 4.1. Working with Intent classes
        1. 4.1.1. Defining intents
        2. 4.1.2. Intent resolution
          1. Action and Categories
          2. Data
        3. 4.1.3. Matching a custom URI
        4. 4.1.4. Using Android-provided activities
      2. 4.2. Listening in with broadcast receivers
        1. 4.2.1. Overloading the Intent concept
        2. 4.2.2. Creating a receiver
      3. 4.3. Building a Service
        1. 4.3.1. Dual-purpose nature of a Service
        2. 4.3.2. Creating a background task Service
      4. 4.4. Performing Inter-Process Communication
        1. 4.4.1. Android Interface Definition Language
        2. 4.4.2. Exposing a remote interface
        3. 4.4.3. Binding to a Service
        4. 4.4.4. Starting versus binding
        5. 4.4.5. Service lifecycle
          1. Service-Started Lifecycle
          2. Service-Bound Lifecycle
          3. Service-Started and -Bound Lifecycle
          4. Cleaning Up When a Service Stops
        6. 4.4.6. Binder and Parcelable
      5. 4.5. Summary
    3. 5. Storing and retrieving data
      1. 5.1. Using preferences
        1. 5.1.1. Working with SharedPreferences
        2. 5.1.2. Preference access permissions
      2. 5.2. Using the filesystem
        1. 5.2.1. Creating files
        2. 5.2.2. Accessing files
        3. 5.2.3. Files as raw resources
        4. 5.2.4. XML file resources
        5. 5.2.5. External storage via an SD card
      3. 5.3. Persisting data to a database
        1. 5.3.1. Building and accessing a database
        2. 5.3.2. Using the sqlite3 tool
      4. 5.4. Working with ContentProvider classes
        1. 5.4.1. Understanding URI representations and manipulating records
          1. Querying Data
          2. Inserting Data
          3. Updating Data
          4. Deleting Data
        2. 5.4.2. Creating a ContentProvider
          1. Defining a Content_Uri and Mime_Type
          2. Extending Contentprovider
          3. Provider Manifests
      5. 5.5. Summary
    4. 6. Networking and web services
      1. 6.1. An overview of networking
        1. 6.1.1. Networking basics
          1. Nodes
          2. Layers and Protocols
          3. IP
          4. TCP and UDP
          5. Application Protocols
        2. 6.1.2. Clients and servers
      2. 6.2. Checking the network status
      3. 6.3. Communicating with a server socket
      4. 6.4. Working with HTTP
        1. 6.4.1. Simple HTTP and java.net
        2. 6.4.2. Robust HTTP with HttpClient
        3. 6.4.3. Creating an HTTP and HTTPS helper
      5. 6.5. Web services
        1. 6.5.1. POX—Putting it together with HTTP and XML
        2. 6.5.2. REST
        3. 6.5.3. To SOAP or not to SOAP, that is the question
      6. 6.6. Summary
    5. 7. Telephony
      1. 7.1. Telephony background and terms
      2. 7.2. Accessing telephony information
        1. 7.2.1. Retrieving telephony properties
        2. 7.2.2. Obtaining phone state information
      3. 7.3. Interacting with the phone
        1. 7.3.1. Using intents to make calls
        2. 7.3.2. Helpful phone number–related utilities
        3. 7.3.3. Intercepting calls
      4. 7.4. Working with messaging: SMS
        1. 7.4.1. Sending SMS messages
        2. 7.4.2. Receiving SMS messages
      5. 7.5. Summary
    6. 8. Notifications and alarms
      1. 8.1. Introducing Toast
      2. 8.2. Introducing notifications
      3. 8.3. Alarms
        1. 8.3.1. Alarm example
      4. 8.4. Summary
    7. 9. Graphics and animation
      1. 9.1. Drawing graphics in Android
        1. 9.1.1. Drawing with XML
      2. 9.2. Animations
        1. 9.2.1. Programmatically creating an animation
          1. Animating Resources
        2. 9.2.2. Introducing OpenGL for embedded systems
          1. Drawing Shapes in OpenGL ES
          2. Three-Dimensional Shapes and Surfaces with OpenGL ES
      3. 9.3. Summary
    8. 10. Multimedia
      1. 10.1. Introduction to multimedia and OpenCORE
      2. 10.2. Playing audio
      3. 10.3. Playing video
      4. 10.4. Capturing media
        1. 10.4.1. Understanding the camera
        2. 10.4.2. Capturing audio
      5. 10.5. Summary
    9. 11. Location, location, location
      1. 11.1. Simulating your location within the emulator
        1. 11.1.1. Sending in your coordinates with the DDMS tool
        2. 11.1.2. The GPS Exchange Format
        3. 11.1.3. The Google Earth Keyhole Markup Language
      2. 11.2. Using LocationManager and LocationProvider
        1. 11.2.1. Accessing location data with LocationManager
        2. 11.2.2. Using a LocationProvider
        3. 11.2.3. Receiving location updates with LocationListener
      3. 11.3. Working with maps
        1. 11.3.1. Extending MapActivity
        2. 11.3.2. Using a MapView
        3. 11.3.3. Placing data on a map with an Overlay
      4. 11.4. Converting places and addresses with Geocoder
      5. 11.5. Summary
  9. 3. Android applications
    1. 12. Putting it all together–the Field Service Application
      1. 12.1. Field Service Application requirements
        1. 12.1.1. Basic requirements
        2. 12.1.2. Data model
        3. 12.1.3. Application architecture and integration
      2. 12.2. Android application tour
        1. 12.2.1. Application flow
        2. 12.2.2. Code road map
        3. 12.2.3. AndroidManifest.xml
      3. 12.3. Android code
        1. 12.3.1. Splash Activity
        2. 12.3.2. FieldService Activity, part 1
          1. Prefs Class
        3. 12.3.3. FieldService Activity, part 2
        4. 12.3.4. Settings
        5. 12.3.5. Data structures
          1. Job XML Description
          2. Jobentry
          3. Joblist
          4. Joblisthandler
      4. 12.4. Digging deeper into the code
        1. 12.4.1. RefreshJobs
        2. 12.4.2. ManageJobs
        3. 12.4.3. ShowJob
        4. 12.4.4. CloseJob
      5. 12.5. Server code
        1. 12.5.1. Dispatcher user interface
        2. 12.5.2. Database
        3. 12.5.3. PHP dispatcher code
        4. 12.5.4. PHP mobile integration code
      6. 12.6. Summary
    2. 13. Hacking Android
      1. 13.1. The Android/Linux:junction
        1. 13.1.1. Tool chain
        2. 13.1.2. Building an application
        3. 13.1.3. Installing and running the application
        4. 13.1.4. Build script
      2. 13.2. A better way
        1. 13.2.1. The static flag, revisited
        2. 13.2.2. Linking
        3. 13.2.3. Exit, not return
        4. 13.2.4. Startup code
      3. 13.3. What time is it?
        1. 13.3.1. Daytime Server application
        2. 13.3.2. daytime.c
        3. 13.3.3. The SQLite database
        4. 13.3.4. Building and running Daytime Server
      4. 13.4. Daytime Client
        1. 13.4.1. Activity
        2. 13.4.2. Socket client
        3. 13.4.3. Testing Daytime Client
      5. 13.5. Summary
  10. A. Installing the Android SDK
    1. A.1. Development environment requirements
    2. A.2. Obtaining and installing Eclipse
    3. A.3. Obtaining and installing the Android SDK
    4. A.4. Obtaining and installing the Eclipse plug-in
    5. A.5. Configuring the Eclipse plug-in
  11. B. Signing and installing applications on an Android device
    1. B.1. Recapping the Android Debug Bridge
    2. B.2. Digital signatures
      1. B.2.1. Keytool
      2. B.2.2. Jarsigner
    3. B.3. Cleaning up for distribution
      1. B.3.1. Important manifest elements: label, logo, version, SDK level
      2. B.3.2. Test, test, then test again
      3. B.3.3. An End User License Agreement
      4. B.3.4. Nice extra: data import and export
    4. B.4. Publishing to the Market
      1. B.4.1. The Market rules
      2. B.4.2. Getting your application in the Market
      3. B.4.3. Automatic Market updates
      4. B.4.4. Why the Market matters
    5. B.5. Other distribution means