Professional Android (Reto Meier, Ian Lake) (Z-Library)

Author: Reto Meier, Ian Lake

技术

The comprehensive developer guide to the latest Android features and capabilities. Professional Android, 4th Edition shows developers how to leverage the latest features of Android to create robust and compelling mobile apps. This hands-on approach provides in-depth coverage through a series of projects, each introducing a new Android platform feature and highlighting the techniques and best practices that exploit its utmost functionality. The exercises begin simply, and gradually build into advanced Android development. Clear, concise examples show you how to quickly construct real-world mobile applications. This book is your guide to smart, efficient, effective Android development. Learn the best practices that get more out of Android. Understand the anatomy, lifecycle, and UI metaphor of Android apps. Design for all mobile platforms, including tablets. Utilize both the Android framework and Google Play services. File: without front cover, 9 blank pages, EULA-page

📄 File Format: PDF
💾 File Size: 18.8 MB
109
Views
0
Downloads
0.00
Total Donations

📄 Text Preview (First 20 pages)

ℹ️

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

📄 Page 1
PROFESSIONAL ANDROID®, FOURTH EDITION INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi CHAPTER 1 Hello, Android . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 CHAPTER 2 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 CHAPTER 3 Applications and Activities and Fragments, Oh My! . . . . . . . . . . . . 57 CHAPTER 4 Defining the Android Manifest and Gradle Build Files, and Externalizing Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 CHAPTER 5 Building User Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 CHAPTER 6 Intents and Broadcast Receivers . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 CHAPTER 7 Using Internet Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 CHAPTER 8 Files, Saving State, and User Preferences . . . . . . . . . . . . . . . . . . . . 245 CHAPTER 9 Creating and Using Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 CHAPTER 10 Content Providers and Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317 CHAPTER 11 Working in the Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 CHAPTER 12 Implementing the Android Design Philosophy . . . . . . . . . . . . . . . . 433 CHAPTER 13 Implementing a Modern Android User Experience . . . . . . . . . . . . 463 CHAPTER 14 Advanced Customization of Your User Interface . . . . . . . . . . . . . . 501 CHAPTER 15 Location, Contextual Awareness, and Mapping . . . . . . . . . . . . . . . 541 CHAPTER 16 Hardware Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619 CHAPTER 17 Audio, Video, and Using the Camera . . . . . . . . . . . . . . . . . . . . . . . 665 CHAPTER 18 Communicating with Bluetooth, NFC, and Wi-Fi Peer-to-Peer . . . 713 CHAPTER 19 Invading the Home Screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 743 CHAPTER 20 Advanced Android Development . . . . . . . . . . . . . . . . . . . . . . . . . . 787 CHAPTER 21 Releasing, Distributing, and Monitoring Applications . . . . . . . . . . 825 INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 863
📄 Page 2
PROFESSIONAL Android® Fourth Edition
📄 Page 3
PROFESSIONAL Android® Fourth Edition Reto Meier Ian Lake
📄 Page 4
Professional Android ®, Fourth Edition Published by John Wiley & Sons, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2018 by John Wiley & Sons, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-1-118-94952-8 ISBN: 978-1-118-94954-2 (ebk) ISBN: 978-1-118-94953-5 (ebk) Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or pro- motional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the pub- lisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with stan- dard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://book- support.wiley.com. For more information about Wiley products, visit www.wiley.com. Library of Congress Control Number: 2018951986 Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trade- marks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Android is a registered trademark of Google, LLC All other trademarks are the property of their respective owners. John Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book.
📄 Page 5
To Kris. —Reto To Andrea and Hannah. —Ian
📄 Page 6
ABOUT THE AUTHORS RETO MEIER has been working to help Android developers create the best applications possible for their users since the initial Android release in 2007. Reto grew up in Perth, Western Australia, and then spent “the next 18 months” in London for a total of 6 years, before settling in the San Francisco Bay Area with his wife in 2011. Reto has spent 10 years as a Developer Advocate at Google, contributing articles, online training, conference talks, and YouTube videos to the developer community. Before smartphones were invented, Reto spent over 10 years as a software developer in various industries, including offshore oil and gas and finance. You can learn more about Reto’s thoughts on Android development, ask him questions, and see pic- tures of his cats on Twitter at www.twitter.com/retomeier, where he shares more than he prob- ably should, and read longer thoughts on Medium at medium.com/@retomeier. IAN LAKE has lived in nine states across the United States before settling in the San Francisco Bay Area in 2013. Ian is a member of the Android Toolkit team at Google, focused on providing the libraries and APIs needed for modern Android development. His prior experience includes that as an Android Developer Advocate, Android app developer, and enterprise application developer back when Android wasn’t even an option. You can connect with Ian on Google+ (plus.google.com/+IanLake) or Twitter (www.twitter .com/ianhlake) to learn more about his wonderful family, hobbies (mostly Android development), and interests. While Reto and Ian work at Google, the views and opinions expressed in this book are theirs alone and do not necessarily represent those of their employer.
📄 Page 7
ABOUT THE TECHNICAL EDITORS DANIEL ULERY is a Senior Software Engineer who lives near Lewiston, Idaho. His experience includes software engineering projects using technologies such as Java Enterprise, C# WinForms, SQL Server, Raspberry Pi, and Android. Dan received his Bachelor of Science in Computer Science from the University of Idaho in 2004. When he’s not working on software projects, he’s likely working on one of many DIY projects. ED WOODWARD is a Senior Development Manager and Android Developer for OpenStax at Rice University. He currently manages the Devops team and is tech lead on the Business Intelligence team along with developing OpenStax’s Android app. Prior to joining OpenStax, Ed was a Vice President/ Application Architect at JPMorganChase. Ed was a Band Director at the high school and middle school level for several years before transitioning to programming. CHAIM KRAUSE is an expert computer programmer with more than 30 years of experience to prove it. He has worked as a lead tech support engineer for ISPs as early as 1995, as a senior developer support engineer with Borland for Delphi, and has worked in Silicon Valley for over a decade in various roles, including technical support engineer and developer support engineer. He is currently a military simulation specialist for the US Army’s Command and General Staff College, working on projects such as developing serious games for use in training exercises. He has also authored several video training courses on Linux topics, and has been a technical reviewer for over 20 books, includ- ing Amazon Web Services for Mobile Developers (Sybex, 2017) and Professional Swift (Wrox, 2015). It seems only natural then that he would be an avid gamer and have his own electronics lab and server room in his basement. He currently resides in Leavenworth, Kansas, with his beautiful partner Ivana and a menagerie of four-legged companions: their two dogs, Dasher and Minnie, and their three cats, Pudems, Talyn, and Alaska. MURAT YENER is a code geek, open source committer, Java Champion, and ex-Google Developer Expert on Android, who is working at Google. He is the author of Expert Android Studio (Wiley, 2016) and Professional Java EE Design Patterns (Wiley, 2015). He has extensive experience with developing Android, Java, web, JavaEE, and OSGi applications, in addition to teaching courses and mentoring. Murat was an Eclipse committer and one of the initial committers of the Eclipse Libra project. Murat had been a user group leader at GDG Istanbul and in GDG San Francisco, organiz- ing, participating, and speaking at events. He is also a regular speaker at major conferences, such as DroidCon, JavaOne, and Devoxx.
📄 Page 8
PROJECT EDITOR John Sleeva TECHNICAL EDITORS Daniel Ulery Ed Woodward Chaim Krause Murat Yener PRODUCTION EDITOR Barath Kumar Rajasekaran COPY EDITOR Kimberly A. Cofer PRODUCTION MANAGER Kathleen Wisor CONTENT ENABLEMENT AND OPERATIONS MANAGER Pete Gaughan MARKETING MANAGER Christie Hilbrich EXECUTIVE EDITOR Jim Minatel PROJECT COORDINATOR, COVER Brent Savage PROOFREADER Nancy Bell INDEXER Johnna VanHoose Dinse COVER DESIGNER Wiley COVER IMAGE © 1971yes/iStock.com CREDITS
📄 Page 9
ACKNOWLEDGMENTS FIRST, I’D LIKE TO THANK MY WIFE KRISTY, whose love and support makes everything I do possible. A big thank you to my friends and colleagues at Google, particularly all the amazing people in the Android team, without whom I’d have nothing to write about, and the developer relations team who inspire me every day. I also thank our army of technical editors, including Dan Ulery, Ed Woodward, Chaim Krause, Murat Yener, James Harmon, and Chad Darby, without whom this book would contain far more errors than it does. Those that remain are entirely my fault. Thank you to the whole team at Wrox, especially John Sleeva and Jim Minatel, whose patience and support in getting this book completed was non-trivial. An extra big thank you goes out to the incredible Android community, made up of passionate, gen- erous, and hard working developers who seem to spend as much time helping each other as they do building amazing apps. Your efforts have been critical in making Android the huge success that it is. Thank you. —Reto MY FAMILY, ANDREA AND HANNAH, are what make everything worth it. Without their support, I wouldn’t be able to do much of anything, much less write this book. I’d like to echo Reto’s thanks for everyone involved in publishing and making this book a reality, the Android team for giving us plenty to talk about, and the Android developer community for sharing our passion around building better apps. —Ian
📄 Page 10
CONTENTS INTRODUCTION xxxi ChapTEr 1: hELLO, aNDrOID 1 Android Application Development 1 A Little Background 2 The Not-So-Distant Past 3 Living in the Future 3 The Android Ecosystem 3 Pre-installed Android Applications 4 Android SDK Features 5 What Does Android Run On? 6 Why Develop for Mobile? 6 Why Develop for Android? 7 Introducing the Development Framework 7 What Comes in the Box 8 Understanding the Android Software Stack 8 The Android Run Time 10 Android Application Architecture 11 Android Libraries 12 ChapTEr 2: GETTING STarTED 13 Getting Started Developing Android Apps 14 Developing for Android 15 What You Need to Begin 15 Creating Your First Android Application 20 Getting Started Writing Android Apps Using Kotlin 35 Using the Android Support Library Package 36 Developing for Mobile and Embedded Devices 39 Hardware-Imposed Design Considerations 39 Considering the User’s Environment 43 Developing for Android 44 Android Development Tools 48 Android Studio 49 The Android Virtual Device Manager 51 The Android Emulator 51
📄 Page 11
xviii CONTENTS Android Profiler 52 The Android Debug Bridge 54 APK Analyzer 54 The Lint Tool 55 Monkey, Monkey Runner, and Espresso UI Testing 55 Gradle 56 ChapTEr 3: appLICaTIONS aND aCTIVITIES aND FraGMENTS, Oh MY! 57 Applications, Activities, and Fragments 58 The Components of an Android Application 58 The Android Application Life Cycle, Priority, and Process States 59 Introducing the Android Application Class 61 A Closer Look at Android Activities 61 Creating Activities 62 Using the AppCompatActivity 63 The Activity Life Cycle 64 Responding to Memory Pressure 71 Introducing Fragments 73 Creating New Fragments 73 The Fragment Life Cycle 74 Introducing the Fragment Manager 79 Adding Fragments to Activities 79 Communicating Between Fragments and Activities 85 Fragments Without User Interfaces 86 Building an Earthquake Viewer Application 87 ChapTEr 4: DEFINING ThE aNDrOID MaNIFEST aND GraDLE BUILD FILES, aND EXTErNaLIZING rESOUrCES 95 The Manifest, Build Files, and Resources 96 Introducing the Android Manifest 96 Configuring the Gradle Build 101 Gradle Settings File 101 Project Gradle Build File 102 Module Gradle Build Files 102 Externalizing Resources 107 Creating Resources 108 Using Resources 119 Creating Resources for Different Languages and Hardware 122 Runtime Configuration Changes 126
📄 Page 12
xix CONTENTS ChapTEr 5: BUILDING USEr INTErFaCES 129 Fundamental Android Design 130 Density-Independent Design 130 Android User Interface Fundamentals 131 Assigning User Interfaces to Activities 132 Introducing Layouts 132 Defining Layouts 134 Using Layouts to Create Device-Independent User Interfaces 136 Optimizing Layouts 139 The Android Widget Toolbox 143 Working with Lists and Grids 144 Recycler View and Layout Managers 145 Introducing Adapters 146 Returning to the Earthquake Viewer Application 149 Introducing Data Binding 150 Enabling Data Binding 151 Variables in Data Binding 152 Data Binding for the Earthquake Viewer Application 153 Creating New Views 155 Modifying Existing Views 155 Creating Compound Controls 159 Creating Simple Compound Controls as a Layout 161 Creating Custom Views 162 Using Custom Controls 176 ChapTEr 6: INTENTS aND BrOaDCaST rECEIVErS 177 Using Intents and Broadcast Receivers 178 Using Intents to Launch Activities 178 Explicitly Starting New Activities 179 Implicit Intents and Late Runtime Binding 179 Determining If an Intent Will Resolve 180 Returning Results from Activities 181 Using Platform-Native Actions to Launch Activities 184 Creating Intent Filters to Receive Implicit Intents 186 Defining an Intent Filter 186 Using Intent Filters for Plug-Ins and Extensibility 194 Introducing Linkify 198 Native Linkify Link Types 198 Creating Custom Link Strings 199
📄 Page 13
xx CONTENTS Using the Match Filter 200 Using the Transform Filter 200 Using Intents to Broadcast Events 200 Broadcasting Events with Intents 201 Listening for Intent Broadcasts with Broadcast Receivers 202 Registering Broadcast Receivers in Code 203 Registering Broadcast Receivers in Your Application Manifest 204 Managing Manifest Receivers at Run Time 204 Monitoring Device State Changes Through Broadcast Intents 205 Introducing the Local Broadcast Manager 207 Introducing Pending Intents 208 ChapTEr 7: USING INTErNET rESOUrCES 211 Connecting to the Internet 211 Connecting, Downloading, and Parsing Internet Resources 212 Why Build a Native Internet App? 212 Connecting to an Internet Resource 213 Performing Network Operations on Background Threads Using View Models, Live Data, and Asynchronous Tasks 214 Parsing XML Using the XML Pull Parser 219 Connecting the Earthquake Viewer to the Internet 220 Parsing JSON Using the JSON Parser 228 Using the Download Manager 233 Downloading Files 233 Customizing Download Manager Notifications 235 Specifying a Download Location 237 Canceling and Removing Downloads 238 Querying the Download Manager 238 Best Practices for Downloading Data Without Draining the Battery 241 An Introduction to Internet Services and Cloud Computing 242 ChapTEr 8: FILES, SaVING STaTE, aND USEr prEFErENCES 245 Saving Files, States, and Preferences 246 Saving and Restoring Activity and Fragment Instance State Using the Lifecycle Handlers 246 Retaining Instance State with Headless Fragments and View Models 248 View Models and Live Data 248 Headless Fragments 251 Creating and Saving Shared Preferences 252 Retrieving Shared Preferences 253
📄 Page 14
xxi CONTENTS Introducing On Shared Preference Change Listeners 254 Configuring Auto Backup of Application Files and Shared Preferences 254 Building a Preference UI 256 Using the Preference Support Library 256 Defining a Preference Screen Layout in XML 257 Introducing the Preference Fragment 260 Creating a Settings Activity for the Earthquake Monitor 261 Including Static Files as Resources 267 Working with the Filesystem 267 File-Management Tools 267 Creating Files on Application-Specific Internal Storage 268 Creating Files on Application-Specific External Storage 268 Accessing Public Directories Using Scoped Directory Access 270 Sharing Files Using File Provider 274 Creating a File Provider 274 Sharing a File Using a File Provider 275 Receiving a File from a File Provider 275 Accessing Files from Other Applications Using the Storage Access Framework 275 Requesting Temporary Access to Files 276 Requesting Persistent Access to Files 277 Requesting Access to Directories 277 Creating New Files 278 Using URI-Based Permissions 278 ChapTEr 9: CrEaTING aND USING DaTaBaSES 281 Introducing Structured Data Storage in Android 282 Storing Data Using the Room Persistence Library 282 Adding the Room Persistence Library 283 Defining a Room Database 284 Persisting Complex Objects Using Type Convertors 286 Defining Room Database Interactions Using Data Access Objects 288 Performing Room Database Interactions 291 Monitoring Query Result Changes with Live Data 292 Persisting Earthquakes to a Database with Room 294 Working with SQLite Databases 298 Input Validation and SQL Injection 299 Cursors and Content Values 299 Defining a Database Contract 300 Introducing the SQLiteOpenHelper 300
📄 Page 15
xxii CONTENTS Opening Databases with the SQLite Open Helper 302 Opening and Creating Databases Without the SQLite Open Helper 303 Adding, Updating, and Deleting Rows 303 Querying a Database 305 Extracting Values from a Cursor 307 Introducing the Firebase Realtime Database 308 Adding Firebase to Your App 309 Defining a Firebase Database and Defining Access Rules 311 Adding, Modifying, Deleting, and Querying Data from a Firebase Realtime Database 313 ChapTEr 10: CONTENT prOVIDErS aND SEarCh 317 Introducing Content Providers 318 Why Should I Use Content Providers? 318 Creating Content Providers 319 Creating the Content Provider’s Database 320 Registering Content Providers 321 Publishing Your Content Provider’s URI Address 321 Implementing Content Provider Queries 322 Content Provider Transactions 325 Sharing Files Using a Content Provider 327 Adding Permission Requirements to Content Providers 328 Accessing Content Providers with Content Resolvers 330 Querying Content Providers 330 Cancelling Queries 333 Querying for Content Asynchronously with a Cursor Loader 333 Adding, Deleting, and Updating Content 336 Accessing Files Stored in Content Providers 338 Accessing Permission-Restricted Content Providers 339 Using Native Android Content Providers 341 Accessing the Call Log 341 Using the Media Store Content Provider 342 Using the Contacts Content Provider 344 Using the Calendar Content Provider 351 Adding Search to Your Application 354 Defining Your Search Metadata 354 Creating a Search Results Activity 355 Searching a Content Provider 357 Using the Search View Widget 360 Providing Search Suggestions Using a Content Provider 362 Searching the Earthquake Monitor Database 366
📄 Page 16
xxiii CONTENTS ChapTEr 11: WOrKING IN ThE BaCKGrOUND 377 Working in the Background 378 Using Background Threads 379 Using Asynchronous Tasks to Run Tasks Asynchronously 379 Manual Thread Creation Using Handler Threads 383 Scheduling Background Jobs 385 Creating a Job Service for the Job Scheduler 386 Scheduling Jobs with the Job Scheduler 388 Scheduling Jobs with the Firebase Job Dispatcher 391 Scheduling Work with the Work Manager 393 An Earthquake-Monitoring Job Service Example 396 Using Notifications to Notify Users 401 Introducing the Notification Manager 401 Working with Notification Channels 402 Creating Notifications 403 Setting a Notification’s Priority 407 Adding Notification Actions 411 Adding Direct Reply Actions 412 Grouping Multiple Notifications 413 Adding Notifications to the Earthquake Monitor 414 Using Firebase Cloud Messaging 417 Triggering Notifications Remotely with Firebase Notifications 418 Receiving Data with Firebase Cloud Messaging 421 Using Alarms 422 Creating, Setting, and Canceling Alarms 423 Setting an Alarm Clock 424 Introducing Services 424 Using Bound Services 425 Creating a Started Service 427 ChapTEr 12: IMpLEMENTING ThE aNDrOID DESIGN phILOSOphY 433 Introducing the Android Design Philosophy 434 Designing for Every Screen 434 Resolution Independence 435 Supporting and Optimizing for Different Screen Sizes 436 Creating Scalable Graphics Assets 439 Introducing Material Design 445 Thinking in Terms of Paper and Ink 446 Using Color and Keylines as Guides 447 Continuity Through Motion 449
📄 Page 17
xxiv CONTENTS Material Design UI Elements 452 The App Bar 452 Applying Material Design to the Earthquake Monitor 455 Using Cards to Display Content 456 Floating Action Buttons 460 ChapTEr 13: IMpLEMENTING a MODErN aNDrOID USEr EXpErIENCE 463 The Modern Android UI 464 Creating Consistent, Modern User Interfaces Using AppCompat 464 Creating and Applying Themes Using AppCompat 465 Creating Theme Overlays for Specific Views 466 Adding a Menu and Actions to the App Bar 467 Defining a Menu Resource 467 Adding a Menu to an Activity 468 Adding a Menu to a Fragment 469 Updating Menu Items Dynamically 469 Handling Menu Selections 470 Adding Action Views and Action Providers 470 Going Beyond the Default App Bar 472 Replacing Your App Bar with a Toolbar 472 Advanced Scrolling Techniques for the Toolbar 473 Incorporating Menus Without the App Bar 476 Improving the Earthquake Monitor’s App Bar 477 App Navigation Patterns 479 Navigating with Tabs 479 Implementing a Bottom Navigation Bar 482 Using a Navigation Drawer 485 Combining Navigation Patterns 491 Adding Tabs to the Earthquake Monitor 492 Choosing the Right Level of Interruption 496 Initiating a Dialog 497 Let’s Make a Toast 498 Inline Interruptions with Snackbars 499 ChapTEr 14: aDVaNCED CUSTOMIZaTION OF YOUr USEr INTErFaCE 501 Expanding the User Experience 502 Supporting Accessibility 502
📄 Page 18
xxv CONTENTS Supporting Navigation Without a Touch Screen 502 Providing a Textual Description of Each View 503 Introducing Android Text-to-Speech 503 Using Speech Recognition 505 Using Speech Recognition for Voice Input 506 Using Speech Recognition for Search 507 Controlling Device Vibration 508 Going Full Screen 508 Working with Property Animations 510 Enhancing Your Views 513 Advanced Canvas Drawing 514 Creating Interactive Controls 530 Composite Drawable Resources 536 Transformative Drawables 536 Layer Drawables 537 State List Drawables 537 Level List Drawables 538 Copy, Paste, and the Clipboard 539 Copying Data to the Clipboard 539 Pasting Clipboard Data 539 ChapTEr 15: LOCaTION, CONTEXTUaL aWarENESS, aND MappING 541 Adding Location, Maps, and Contextual Awareness to Your Applications 542 Introducing Google Play Services 542 Adding Google Play Services to Your Application 543 Determining the Availability of Google Play Services 545 Finding Device Location Using Google Location Services 546 Using the Emulator to Test Location-Based Functionality 548 Finding the Last Known Location 549 “Where Am I” Example 551 Requesting Location Change Updates 555 Changing Device Location Settings 560 Updating the Location in the “Where Am I” Example 563 Best Practices When Using Location 566 Setting and Managing Geofences 567 Using the Legacy Platform Location-Based Services 571 Selecting a Location Provider 572 Finding the Last Known Location 574
📄 Page 19
xxvi CONTENTS Requesting Location Change Updates 575 Best Practice for Using the Legacy Location-Based Services 577 Using the Geocoder 580 Reverse Geocoding 581 Forward Geocoding 582 Geocoding Where Am I 583 Creating Map-Based Activities 585 Getting Your Maps API Key 586 Creating a Map-Based Activity 586 Configuring Google Maps 589 Changing the Camera Position with Camera Updates 590 Mapping Where Am I 592 Displaying the Current Location with the My Location Layer 596 Displaying Interactive Map Markers 596 Adding Shapes to Google Maps 599 Adding Image Overlays to Google Maps 602 Adding Markers and Shapes to Where Am I 602 Mapping the Earthquake Example 605 Adding Contextual Awareness 609 Connecting to the Google Play Services API Client and Obtaining API Keys 610 Using Awareness Snapshots 612 Setting and Monitoring Awareness Fences 613 Awareness Best Practices 617 ChapTEr 16: harDWarE SENSOrS 619 Introducing Android Sensors 620 Using the Sensor Manager 620 Understanding the Android Sensors 621 Discovering and Identifying Sensors 623 Determining Sensor Capabilities 625 Wakeup and Non-Wakeup Sensors 627 Monitoring Sensor Results 627 Interpreting Sensor Values 632 Testing Sensors with the Android Virtual Device and Emulator 635 Best Practices for Working with Sensors 637 Monitoring a Device’s Movement and Orientation 637 Determining the Natural Orientation of a Device 638 Introducing Accelerometers 639 Detecting Acceleration Changes 640 Creating a Gravitational Force Meter 642 Determining a Device’s Orientation 645 Creating a Compass and Artificial Horizon 650
📄 Page 20
xxvii CONTENTS Using the Environmental Sensors 654 Using the Barometer Sensor 654 Creating a Weather Station 655 Using Body Sensors 659 User Activity Recognition 662 ChapTEr 17: aUDIO, VIDEO, aND USING ThE CaMEra 665 Playing Audio and Video, and Using the Camera 666 Playing Audio and Video 666 Introducing the Media Player 667 Using Media Player for Video Playback 669 Using ExoPlayer for Video Playback 672 Requesting and Managing Audio Focus 674 Pausing Playback When the Output Changes 676 Responding to the Volume Controls 677 Working with a Media Session 678 Using the Media Router and Cast Application Framework 682 Background Audio Playback 686 Building an Audio Playback Service 686 Using a Media Browser to Connect Your Activity to a Media Browser Service 688 Life Cycle of a Media Browser Service 690 Playing Audio as a Foreground Service 691 Creating Media Style Notifications 693 Using the Media Recorder to Record Audio 695 Using the Camera for Taking Pictures 697 Using Intents to Take Pictures 697 Controlling the Camera Directly 699 Reading and Writing JPEG EXIF Image Details 706 Recording Video 706 Using Intents to Record Video 707 Using the Media Recorder to Record Video 707 Adding Media to the Media Store 710 Inserting Media Using the Media Scanner 710 Inserting Media Manually 711 ChapTEr 18: COMMUNICaTING WITh BLUETOOTh, NFC, aND WI-FI pEEr-TO-pEEr 713 Networking and Peer-to-Peer Communication 713 Transferring Data Using Bluetooth 714 Managing the Local Bluetooth Device Adapter 714 Being Discoverable and Remote Device Discovery 716
The above is a preview of the first 20 pages. Register to read the complete e-book.

💝 Support Author

0.00
Total Amount (¥)
0
Donation Count

Login to support the author

Login Now
Back to List