Android 9 Development Cookbook - Third Edition

Book Description

Build feature-rich, reliable Android Pie apps with the help of more than 100 proven industry standard recipes and strategies.

Key Features

  • Uncover the latest features in Android 9 Pie to make your applications stand out
  • Develop Android Pie applications with the latest mobile technologies, from set up to security
  • Get up-to-speed with Android Studio 3 and its impressive new features

Book Description

The Android OS has the largest installation base of any operating system in the world. There has never been a better time to learn Android development to write your own applications, or to make your own contributions to the open source community! With this extensively updated cookbook, you'll find solutions for working with the user interfaces, multitouch gestures, location awareness, web services, and device features such as the phone, camera, and accelerometer. You also get useful steps on packaging your app for the Android Market. Each recipe provides a clear solution and sample code you can use in your project from the outset. 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 Pie.

What you will learn

  • Develop applications using the latest Android framework while maintaining backward-compatibility with the support library
  • Create engaging applications using knowledge gained from recipes on graphics, animations, and multimedia
  • Work through succinct steps on specifics that will help you complete your project faster
  • Add location awareness to your own app with examples using the latest Google Play services API
  • Utilize Google Speech Recognition APIs for your app

Who this book is for

If you are new to Android development and want to take a hands-on approach to learning the framework, or if you are an experienced developer in need of clear working code to solve the many challenges in Android development, you will benefit from this book. Either way, this is a resource you'll want to keep on your desk as a quick reference to help you solve new problems as you tackle more challenging projects.

Publisher Resources

Download Example Code

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Android 9 Development Cookbook Third Edition
  3. Dedication
  4. About Packt
    1. Why subscribe?
    2. Packt.com
  5. Contributors
    1. About the author
    2. About the reviewers
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Get in touch
      1. Reviews
  7. 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...
      5. See also
    4. Switching between activities
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Passing data to another activity
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Returning a result from an activity
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Saving an activity's state
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. 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
    9. Understanding the activity life cycle
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  8. Layouts
    1. Introduction
    2. Defining and inflating a layout
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Using RelativeLayout
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Using LinearLayout
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Creating tables – TableLayout and GridLayout
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. RecyclerView replaces ListView
      1. Getting ready
      2. How to do it...
      3. How it works…
      4. There’s more…
    7. Changing layout properties during runtime
      1. Getting ready
      2. How to do it...
      3. How it works...
  9. Views, Widgets, and Styles
    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...
      5. See also
    3. Using graphics to show button state
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Using designated folders for screen-specific resources
      5. See also
    4. Creating a widget at runtime
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Creating a custom component
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Applying a style to a View
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Turning a style into a theme
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Selecting a theme based on the Android version
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  10. Menus and Action Mode
    1. Introduction
    2. Creating an options menu
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Using a menu item to launch an activity
        2. Creating submenus
        3. Grouping menu items
      5. See also
    3. Modifying menus and menu items during runtime
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Enabling Contextual Action Mode for a view
      1. Creating a floating context menu
      2. Getting ready
      3. How to do it...
      4. How it works...
      5. There's more...
      6. See also
    5. Using Contextual Batch Mode with RecyclerView
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Creating a pop-up menu
      1. Getting ready
      2. How to do it...
      3. How it works...
  11. Fragments
    1. Introduction
    2. Creating and using a Fragment
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Adding and removing Fragments during runtime
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Passing data between Fragments
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Handling the Fragment back stack
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  12. Home Screen Widgets, Search, and the System UI
    1. Introduction
    2. Creating a shortcut on the Home screen
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Creating a Home screen widget
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Adding Search to the Action Bar
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Showing your app full-screen
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Sticky Immersion
        2. Dimming the System UI
        3. Setting the Action Bar as an overlay
        4. Translucent system bars
      5. See also
  13. Data Storage
    1. Introduction
    2. Storing simple data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Read and write a text file to internal storage
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Caching files
      5. See also
    4. Read and write a text file to external storage
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Getting public folders
        2. Checking available space
        3. Deleting a file
        4. Working with directories
        5. Preventing files from being included in galleries
      5. See also
    5. Including resource files in your project
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Creating and using an SQLite database
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Upgrading a database
      5. See also
    7. Accessing data in the background using a Loader
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Accessing external storage with scoped directories in Android N
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  14. Alerts and Notifications
    1. Introduction
    2. Lights, Action, and Sound – getting the user's attention!
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Creating a Toast with a custom layout
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Displaying a message box with AlertDialog
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Add an icon
        2. Using a list
        3. Custom layout
    5. Displaying a progress dialog
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Lights, Action, and Sound Redux using Notifications
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Adding a button to the notification using addAction()
        2. Expanded notifications
        3. Lock screen notifications
      5. See also
    7. Creating a Media Player Notification
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Making a Flashlight with a Heads-Up Notification
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. Notifications with Direct Reply
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  15. Using the Touchscreen and Sensors
    1. Introduction
    2. Listening for click and long-press events
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Recognizing tap and other common gestures
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Pinch-to-zoom with multi-touch gestures
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Swipe-to-Refresh
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Listing available sensors – an introduction to the Android Sensor Framework
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Reading sensor data – using Android Sensor Framework events
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Environment sensors
        2. Position sensors
        3. Motion sensors
      5. See also
    8. Reading device orientation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Getting current device rotation
      5. See also
  16. Graphics and Animation
    1. Introduction
    2. Scaling down large images to avoid Out of Memory exceptions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. A transition animation – defining scenes and applying a transition
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Creating a Compass using sensor data and RotateAnimation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Creating a slideshow with ViewPager
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Creating a Setup Wizard
      5. See also
    6. Creating a Card Flip Animation with Fragments
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Creating a Zoom Animation with a Custom Transition
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Getting the default animation duration
      5. See also
    8. Displaying animated image (GIF/WebP) with the new ImageDecoder library
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Creating a circle image with the new ImageDecoder
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  17. A First Look at OpenGL ES
    1. Introduction
    2. Setting up the OpenGL ES environment
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. Declaring OpenGL in the Android Manifest
        2. Extending the GLSurfaceView class
        3. Creating an OpenGL rendered class
      4. There's more...
    3. Drawing shapes on GLSurfaceView
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Applying the projection and camera view while drawing
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Moving the triangle with rotation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. The render mode
    6. Rotating the triangle with user input
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  18. Multimedia
    1. Introduction
    2. Playing sound effects with SoundPool
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Playing audio with MediaPlayer
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Playing music in the background
        2. Using hardware volume keys to control your app's audio volume
      5. See also
    4. Responding to hardware media controls in your app
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Checking the hardware type
      5. See also
    5. Taking a photo with the default camera app
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Calling the default video app
      5. See also
    6. Taking a picture using the Camera2 API
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. Setting up the camera preview
        2. Capturing the image
      4. There's more...
      5. See also
  19. Telephony, Networks, and the Web
    1. Introduction
    2. How to make a phone call
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Monitoring phone call events
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. How to send SMS (text) messages
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Multipart messages
        2. Delivery status notification
      5. See also
    5. Receiving SMS messages
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Reading existing SMS messages
      5. See also
    6. Displaying a web page in your application
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Controlling page navigation
        2. How to enable JavaScript
        3. Enable built-in zoom
      5. See also
    7. Checking online status and connection type
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Monitoring network state changes
      5. See also
    8. Phone number blocking API
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  20. Location and Using Geofencing
    1. Introduction
    2. How to get the device location
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Mock locations
      5. See also
    3. Resolving problems reported with the GoogleApiClient OnConnectionFailedListener
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Creating and monitoring a Geofence
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  21. Getting Your App Ready for the Play Store
    1. Introduction
    2. The Android 6.0 Runtime Permission Model
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. How to schedule an alarm
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Cancel the alarm
        2. Repeating alarm
      5. See also
    4. Receiving notification of device boot
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Using the AsyncTask for background work
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Parameter types
        2. Canceling the task
      5. See also
    6. Adding speech recognition to your app
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. How to add Google sign-in to your app
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  22. Getting Started with Kotlin
    1. Introduction
    2. How to create an Android project with Kotlin
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Creating a Toast in Kotlin
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Runtime permission in Kotlin
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  23. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product Information

  • Title: Android 9 Development Cookbook - Third Edition
  • Author(s): Rick Boyer
  • Release date: October 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788991216