You are previewing Android 3.0 Application Development Cookbook.
O'Reilly logo
Android 3.0 Application Development Cookbook

Book Description

Over 70 working recipes covering every aspect of Android development

  • Written for Android 3.0 but also applicable to lower versions

  • Quickly develop applications that take advantage of the very latest mobile technologies, including web apps, sensors, and touch screens

  • Part of Packt's Cookbook series: Discover tips and tricks for varied and imaginative uses of the latest Android features

In Detail

Android is a mobile operating system that runs on a staggering number of smartphones and tablets. Android offers developers the ability to build extremely rich and innovative applications written using the Java programming language. Among the number of books that have been published on the topic, what’s missing is a thoroughly practical, hands-on book that takes you straight to getting your job done without boring you with too much theory.

Android 3.0 Application Development Cookbook will take you straight to the information you need to get your applications up and running. This book is written to provide you with the shortest possible route between an idea and a working application.

Work through the book from start to finish to become an Android expert, or use it as a reference book by applying recipes directly to your project.

This book covers every aspect of mobile app development, starting with major application components and screen layout and design, before moving on to how to manage sensors such as internal gyroscopes and near field communications. Towards the end, it delves into smartphone multimedia capabilities as well as graphics and animation, web access, and GPS.

Whether you are writing your first app or your hundredth, this is a book that you will come back to time and time again, with its many tips and tricks on the rich features of Android 3.

Over 100 working recipes covering every aspect of Android development

Table of Contents

  1. Android 3.0 Application Development Cookbook
    1. Android 3.0 Application Development Cookbook
    2. Credits
    3. About the Author
    4. About the Reviewers
    5. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free access for Packt account holders
    6. Preface
      1. What this book covers
      2. Who this book is for
      3. Conventions
      4. Reader feedback
      5. Customer support
        1. Errata
        2. Piracy
        3. Questions
    7. 1. Activities
      1. Introduction
      2. Declaring an activity
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. Starting a new activity with an intent object
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Setting data and action
          2. Exploring other functions with auto-complete
        5. See also
      4. Switching between activities
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      5. Returning a result from an activity
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Returning an intent with the result code
        5. See also
      6. Storing an activity's state
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Using ID to include a view in the Bundle
        5. See also
      7. Storing persistent activity data
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Using more than one preference file
        5. See also
      8. Managing the activity lifecycle
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Shutting down an activity
    8. 2. Layouts
      1. Introduction
      2. Declaring a layout
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      3. Applying a relative layout
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      4. Applying a table layout
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Columns can shrink as well as stretch
          2. Hiding columns
      5. Using ListViews and ListAdapters
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Setting up a multi-choice ListView
        5. See also
      6. Applying gravity and weight
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      7. Controlling layout during runtime
        1. Getting ready
        2. How to do it....
        3. How it works...
        4. See also
      8. Optimizing for tablets and multiple screens
        1. Getting ready
        2. How to do it....
        3. How it works...
        4. See also
      9. Dividing the screen into fragments
        1. Getting ready
        2. How to do it....
        3. How it works...
        4. See also
      10. Running 3.0 and higher applications on older platforms
        1. Getting ready
        2. How to do it....
        3. How it works...
    9. 3. Widgets
      1. Introduction
      2. Inserting a widget into a layout
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Changing a CheckBox's state with code
        5. See also
      3. Adding images to widgets
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Android will re-size images by default
          2. Using designated folders for screen-specific resources
          3. See also
      4. Creating a widget at runtime
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Using addView() with width and height parameters
      5. Applying a style
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      6. Turning a style into a theme
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Applying a theme to an entire application
      7. Using a platform style or theme
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      8. Creating a custom component
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
    10. 4. Menus
      1. Introduction
      2. Creating and inflating an options menu
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Handling longer options menus
          2. Providing condensed menu titles
          3. Adding Option menu items to the Action Bar
      3. Designing Android compliant menu icons
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      4. Building a context sensitive menu
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Adding menu items dynamically
        5. See also
      5. Handling menu selections
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Selecting context menu items
          2. Starting an activity from a menu
      6. Building menu groups of checkable items
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Changing checkable items dynamically
      7. Applying shortcut keys and submenus
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
    11. 5. Data and Security
      1. Introduction
      2. Using internal storage for private data
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Exploring internal memory
          2. Storing static data
      3. Storing public data on external storage
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Public directories
          2. Preventing files from being included in galleries
      4. Creating a SQLite database
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Making a database thread safe
          2. Versioning a database
      5. Sharing multimedia files across applications with Content Providers
        1. Getting ready
        2. How to do it...
        3. How it works...
      6. Defining and enforcing permissions
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Defining and enforcing custom permissions
        5. See also
      7. Providing backup functionality
        1. Getting ready
        2. How to do it...
        3. How it works...
    12. 6. Detecting User Activity
      1. Introduction
      2. Reading a device's orientation
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. Measuring motion with the accelerometer
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Accessing any available sensor
      4. Listing available sensors
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Recognizing a touch event
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Edge detection
          2. Pressure and size detection
        5. See also
      6. Detecting multi-touch elements
        1. Getting ready
        2. How to do it...
        3. How it works...
      7. Recognizing gestures
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Detecting double-taps
          2. Detecting all gesture events
      8. Handling multi-touch gestures
        1. Getting ready
        2. How to do it...
        3. How it works...
      9. Controlling on screen keyboards
        1. Getting ready
        2. How to do it...
          1. How it works...
          2. There's more...
    13. 7. Notifying the User
      1. Introduction
      2. Displaying an alert dialog
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Adding an icon to an alert dialog
          2. Employing lists in dialogs
          3. Listening for dialog cancellations and dismissals
        5. See also
      3. Displaying a progress dialog
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      4. Customizing a dialog
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      5. Making a Toast
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Customizing Toasts
        5. See also
      6. Notifying the user with the status bar
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Adding a sound to a notification
          2. Adding a flashing light to a notification
          3. Adding a vibration to a notification
        5. See also
      7. Using the Notifcation.Builder class
        1. Getting ready
        2. How to do it...
        3. How it works...
    14. 8. Graphics and Animation
      1. Introduction
      2. Adding graphics to the ImageView class
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Setting an image's maximum dimensions
          2. Controlling an image's aspect ratio
        5. See also
      3. Rotating an image with a matrix
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      4. Using ShapeDrawable and Paint
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      5. Drawing with a Canvas
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      6. Using tween animations
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      7. Animating with Honeycomb APIs
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      8. Creating stop frame animations
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Using window focus to trigger an animation
      9. Working with OpenGL
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. The Renderscript system
          2. Hardware acceleration
    15. 9. Multimedia
      1. Introduction
      2. Playing an audio file from within an application
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Playing back a file or a stream
        5. See also
      3. Playing back video from external memory
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Adding a MediaPlayerControl to a view
      4. Playing multiple sounds with a SoundPool
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Recording audio
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      6. Recording video
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      7. Capturing photos with the camera
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
    16. 10. Telephony, Networks, and the Web
      1. Introduction
      2. Initiating a phone call
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. Listening for phone events
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Sending SMS messages
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Sending long text messages
          2. Sending data with SMS
        5. See also
      5. Monitoring SMS messages
        1. Getting ready
        2. How to do it...
        3. How it works...
      6. Connecting to WiFi
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Checking the WiFi state
          2. Listing all configured WiFi networks
      7. Connecting Bluetooth devices
        1. Getting ready
        2. How to do it...
        3. How it works...
      8. Including web content
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Opening the browser at a specific page
          2. Rendering HTML in a WebView
        5. See also
    17. 11. GPS, Locations, and Maps
      1. Introduction
      2. Detecting a device's location
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Obtaining a location with a network provider
        5. See also
      3. Listening for location changes
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      4. Setting up Google Maps
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Zooming in on a MapView
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Zooming to a fixed point on a MapView
      6. Setting a map's location with a GeoPoint
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      7. Marking a location on a map with an overlay
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also