1. Trang chủ
  2. » Giáo Dục - Đào Tạo

21 2 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 21
Dung lượng 7,06 MB

Nội dung

FOURTH EDITION wrox Fdroid Reto Meier and Ian Lake PROFESSIONAL ANDROID@,FOURTH EDITION xxxi INTRODUCTION CHAPTER CHAPTER CHAPTER CHAPTER Hello, Android Getting Started 13 Applications and Activities and Fragments, Oh My! Defining the Android Manifest and Gradle Build Files, and Externalizing Resources 57 CHAPTER CHAPTER Building User Interfaces CHAPTER CHAPTER CHAPTER CHAPTER 10 CHAPTER 11 CHAPTER 12 CHAPTER 13 CHAPTER 14 CHAPTER 15 CHAPTER 16 CHAPTER 17 CHAPTER 18 CHAPTER 19 CHAPTER 20 CHAPTER 21 Using Internet Resources Files, Saving State, and User Preferences INDEX Intents and Broadcast Receivers 95 129 177 211 245 Creating and Using Databases Content Providers and Search 281 Working in the Background Implementing the Android Design Philosophy 377 Implementing a Modern Android User Experience Advanced Customization of Your User Interface Location, Contextual Awareness, and Mapping 317 433 463 501 541 HardwareSensors 619 Audio, Video, and Using the Camera Communicating with Bluetooth, NFC, and Wi-Fi Peer-to-Peer 665 Invading the Home Screen Advanced Android Development Releasing, Distributing, and Monitoring Applications 713 743 787 825 863 PROFESSIONAL Android@ Fourth Edition Reto Meier Ian Lake wrox A Wiley Brand CONTENTS INTRODUCTION CHAPTER 1: HELLO, ANDROID Android Application Development A Little Background The Not-So-Distant Past Living in the Future The Android Ecosystem Pre-installed Android Applications Android SDK Features What Does Android Run On? Why Develop for Mobile? Why Develop for Android? Introducing the Development Framework What Comes in the Box Understanding the Android Software Stack The Android Run Time Android Application Architecture Android Libraries CHAPTER 2: GETTING STARTED Getting Started Developing Android Apps Developing for Android What You Need to Begin Creating Your First Android Application Getting Started Writing Android Apps Using Kotlin Using the Android Support Library Package Developing for Mobile and Embedded Devices Hardware-imposed Design Considerations Considering the User's Environment Developing for Android Android Development Tools Android Studio The Android Virtual Device Manager The Android Emulator xxxi 1 3 6 7 8 10 11 12 13 14 15 15 20 35 36 39 39 44 48 49 51 51 t CONTENTS Android Profiler The Android Debug Bridge APK Analyzer The Lint Tool Monkey, Monkey Runner, and Espresso UI Testing Gradle CHAPTER 3: APPLICATIONS AND ACTIVITIES AND FRAGMENTS, OH MY! Applications, Activities, and Fragments The Components of an Android Application The Android Application Life Cycle, Priority, and Process States Introducing the Android Application Class A Closer Look at Android Activities Creating Activities Using the AppCompatActivity The Activity Life Cycle Responding to Memory Pressure Introducing Fragments Creating New Fragments The Fragment Life Cycle Introducing the Fragment Manager Adding Fragments to Activities Communicating Between Fragments and Activities Fragments Without User Interfaces Building an Earthquake Viewer Application CHAPTER 4: DEFININGTHE ANDROID MANIFEST AND CRADLE BUILD FILES, AND EXTERNALIZING RESOURCES The Manifest, Build Files, and Resources Introducing the Android Manifest Configuring the Gradle Build Gradle Settings File Project Gradle Build File Module Gradle Build Files Externalizing Resources Creating Resources Using Resources Creating Resources for Different Languages and Hardware Runtime Configuration Changes xviii 52 54 54 55 55 56 57 58 58 59 61 61 62 63 64 71 73 73 79 79 85 86 87 95 96 96 101 101 102 102 107 108 119 122 126 CONTENTS CHAPTER 5: BUILDING USER INTERFACES 129 Fundamental Android Design Density-Independent Design Android User Interface Fundamentals 130 Assigning User Interfaces to Activities Introducing Layouts Defining Layouts Using Layouts to Create Device-independent User Interfaces Optimizing Layouts The Android Widget Toolbox Working with Lists and Grids Recycler View and Layout Managers Introducing Adapters Returning to the Earthquake Viewer Application Introducing Data Binding Enabling Data Binding Variables in Data Binding Data Binding for the Earthquake Viewer Application Creating New Views 130 131 132 132 134 136 139 143 144 145 146 149 150 151 152 153 155 Modifying Existing Views Creating Compound Controls Creating Simple Compound Controls as a Layout Creating Custom Views Using Custom Controls 155 159 CHAPTER 6: INTENTS AND BROADCAST RECEIVERS 177 Using Intents and Broadcast Receivers Using Intents to Launch Activities Explicitly Starting New Activities Implicit Intents and Late Runtime Binding Determining If an Intent Will Resolve Returning Results from Activities Using Platform-NativeActions to Launch Activities Creating Intent Filters to Receive Implicit Intents Defining an Intent Filter Using Intent Filters for Plug-Ins and Extensibility Introducing Linkify Native Linkify Link Types Creating Custom Link Strings 161 162 176 178 178 179 179 180 181 186 186 194 198 198 199 xix CONTENTS Using the Match Filter Using the Transform Filter 200 200 200 Broadcasting Events with Intents Listening for Intent Broadcasts with Broadcast Receivers 201 Using Intents to Broadcast Events Registering Broadcast Receivers in Code Registering Broadcast Receivers in Your Application Manifest Managing Manifest Receivers at Run Time Monitoring Device State Changes Through Broadcast Intents Introducing the Local Broadcast Manager Introducing Pending Intents CHAPTER 7: USING INTERNET RESOURCES Connecting to the Internet Connecting, Downloading, and Parsing Internet Resources Why Build a Native Internet App? Connecting to an Internet Resource Performing Network Operations on Background Threads Using View Models, Live Data, and Asynchronous Tasks Parsing XML Using the XML Pull Parser Connecting the Earthquake Viewer to the Internet Parsing JSON Using the JSON Parser Using the Download Manager Downloading Files Customizing Download Manager Notifications Specifying a Download Location Canceling and Removing Downloads Querying the Download Manager 202 203 204 204 205 207 208 211 211 212 212 213 214 219 220 228 233 233 235 237 238 238 Best Practices for Downloading Data Without Draining the Battery 241 An Introductionto InternetServices and Cloud Computing 242 CHAPTER 8: FILES, SAVING STATE, AND USER PREFERENCES Saving Files, States, and Preferences Saving and Restoring Activity and Fragment Instance State Using the Lifecycle Handlers Retaining Instance State with Headless Fragments and View Models View Models and Live Data Headless Fragments Creating and Saving Shared Preferences Retrieving Shared Preferences 245 246 246 248 248 251 252 253 CONTENTS Introducing On Shared Preference Change Listeners Configuring Auto Backup of Application Files and Shared Preferences Building a Preference UI Using the Preference Support Library Defining a Preference Screen Layout in XML Introducing the Preference Fragment 254 254 256 256 257 260 261 Creating a Settings Activity for the Earthquake Monitor Including Static Files as Resources Working with the Filesystem 267 267 File-Management Tools Creating Files on Application-Specific Internal Storage Creating Files on Application-Specific External Storage Accessing Public Directories Using Scoped Directory Access 267 268 268 270 Sharing Files Using File Provider Creating a File Provider Sharing a File Using a File Provider Receiving a File from a File Provider Accessing Files from Other Applications Using the Storage Access Framework Requesting Temporary Access to Files Requesting Persistent Access to Files Requesting Access to Directories Creating New Files Using URI-Based Permissions CHAPTER 9: CREATING AND USING DATABASES Introducing Structured Data Storage in Android Storing Data Using the Room Persistence Library Adding the Room Persistence Library Defining a Room Database Persisting Complex Objects Using Type Convertors Defining Room Database Interactions Using Data Access Objects Performing Room Database Interactions Monitoring Query Result Changes with Live Data Persisting Earthquakes to a Database with Room Working with SQLite Databases Input Validation and SQL Injection Cursors and Content Values Defining a Database Contract Introducing the SQLiteOpenHelper 274 274 275 275 275 276 277 277 278 278 281 282 282 283 284 286 288 291 292 294 298 299 299 300 300 CONTENTS xxii Opening Databases with the SQLite Open Helper Opening and Creating Databases Withoutthe SQLite Open Helper Adding, Updating, and Deleting Rows Querying a Database Extracting Values from a Cursor Introducing the Firebase Realtime Database Adding Firebase to Your App Defining a Firebase Database and Defining Access Rules Adding, Modifying, Deleting, and Querying Data from a Firebase RealtimeDatabase CHAPTER 10: CONTENT PROVIDERSAND SEARCH Introducing Content Providers Why Should I Use Content Providers? Creating Content Providers Creating the Content Provider'sDatabase Registering Content Providers Publishing Your Content Provider's URI Address Implementing Content Provider Queries Content Provider Transactions Sharing Files Using a Content Provider Adding PermissionRequirementsto Content Providers Accessing Content Providers with Content Resolvers Querying Content Providers Cancelling Queries Querying for Content Asynchronously with a Cursor Loader Adding, Deleting, and Updating Content Accessing Files Stored in Content Providers Accessing Permission-Restricted Content Providers Using Native Android Content Providers Accessing the Call Log Using the Media Store Content Provider Using the Contacts Content Provider Using the Calendar Content Provider Adding Search to Your Application Defining Your Search Metadata Creating a Search Results Activity Searching a Content Provider Using the Search View Widget Providing Search Suggestions Using a Content Provider Searching the Earthquake Monitor Database 302 303 303 305 307 308 309 311 313 317 318 318 319 320 321 321 322 325 327 328 330 330 333 333 336 338 339 341 341 342 351 354 354 355 357 360 362 366 CONTENTS CHAPTER 11: WORKING IN THE BACKGROUND Working in the Background Using Background Threads Using Asynchronous Tasks to Run Tasks Asynchronously Manual Thread Creation Using Handler Threads Scheduling Background Jobs Creating a Job Service for the Job Scheduler Scheduling Jobs with the Job Scheduler Scheduling Jobs with the Firebase Job Dispatcher Scheduling Work with the Work Manager An Earthquake-MonitoringJob Service Example Using Notifications to Notify Users Introducing the Notification Manager Working with Notification Channels Creating Notifications Setting a Notification'sPriority Adding Notification Actions Adding Direct Reply Actions Grouping Multiple Notifications Adding Notifications to the Earthquake Monitor Using Firebase Cloud Messaging Triggering Notifications Remotely with Firebase Notifications Receiving Data with Firebase Cloud Messaging Using Alarms Creating, Setting, and Canceling Alarms Setting an Alarm Clock Introducing Services Using Bound Services Creating a Started Service CHAPTER 12: IMPLEMENTING THE ANDROID DESIGN PHILOSOPHY Introducing the Android Design Philosophy Designing for Every Screen Resolution Independence Supporting and Optimizing for Different Screen Sizes Creating Scalable Graphics Assets Introducing Material Design Thinking in Terms of Paper and Ink Using Color and Keylines as Guides Continuity Through Motion 377 378 379 379 383 385 386 388 391 393 396 401 401 402 403 407 411 412 413 414 417 418 421 422 423 424 424 425 427 433 434 434 435 436 439 445 446 447 449 xxiii CONTENTS Material Design UI Elements The App Bar Applying Material Design to the Earthquake Monitor Using Cards to Display Content Floating Action Buttons CHAPTER 13: IMPLEMENTINGA MODERN ANDROID USER EXPERIENCE The ModernAndroid UI Creating Consistent, Modern User Interfaces Using AppCompat Creating and Applying Themes Using AppCompat Creating Theme Overlays for Specific Views Adding a Menu and Actions to the App Bar Defining a Menu Resource Adding a Menuto an Activity Adding a Menuto a Fragment Updating Menu Items Dynamically Handling Menu Selections Adding Action Views and Action Providers Going Beyond the Default App Bar Replacing Your App Bar with a Toolbar Advanced Scrolling Techniques for the Toolbar Incorporating Menus Without the App Bar Improving the Earthquake Monitor's App Bar App Navigation Patterns Navigating with Tabs Implementing a Bottom Navigation Bar Using a Navigation Drawer Combining Navigation Patterns Adding Tabs to the Earthquake Monitor Choosing the Right Level of Interruption Initiating a Dialog Let's Make a Toast Inline Interruptions with Snackbars CHAPTER 14: ADVANCED CUSTOMIZATION OF YOUR USER INTERFACE Expanding the User Experience Supporting Accessibility 452 452 455 456 460 463 464 464 465 466 467 467 468 469 469 470 470 472 472 473 476 477 479 479 482 485 491 492 496 497 498 499 501 502 502 CONTENTS Supporting Navigation Without a Touch Screen Providing a Textual Description of Each View 502 503 Introducing Android Text-to-Speech Using Speech Recognition 503 505 Controlling Device Vibration Going Full Screen Working with Property Animations Enhancing Your Views 508 508 Using Speech Recognition for Voice Input Using Speech Recognition for Search Advanced Canvas Drawing Creating Interactive Controls 506 507 510 513 514 530 Composite Drawable Resources 536 Copy, Paste, and the Clipboard 539 Transformative Drawables Layer Drawables State List Drawables Level List Drawables Copying Data to the Clipboard Pasting Clipboard Data CHAPTER 15: LOCATION, CONTEXTUAL AWARENESS, AND MAPPING 536 537 537 538 539 539 541 Adding Location, Maps, and Contextual Awareness to Your Applications Introducing Google Play Services 542 542 Finding Device Location Using Google Location Services 546 Adding Google Play Services to Your Application Determining the Availability of Google Play Services 543 545 Using the Emulator to Test Location-Based Functionality Finding the Last Known Location 548 549 Requesting Location Change Updates Changing Device Location Settings Updating the Location in the "Where Am I" Example Best Practices When Using Location 555 560 563 566 567 571 572 574 "WhereAm l" Example Setting and Managing Geofences Using the Legacy Platform Location-Based Services Selecting a Location Provider Finding the Last Known Location 551 CONTENTS Requesting Location Change Updates Best Practice for Using the Legacy Location-Based Services Using the Geocoder Reverse Geocoding Forward Geocoding Geocoding Where Am I Creating Map-Based Activities Getting Your Maps API Key Creating a Map-Based Activity Configuring Google Maps Changing the Camera Position with Camera Updates Mapping Where Am I Displaying the Current Location with the My Location Layer Displaying Interactive Map Markers Adding Shapes to Google Maps Adding Image Overlays to Google Maps Adding Markers and Shapes to Where Am I Mapping the Earthquake Example Adding Contextual Awareness Connecting to the Google Play Services API Client and Obtaining API Keys Using Awareness Snapshots Setting and Monitoring Awareness Fences Awareness Best Practices CHAPTER 16: HARDWARE SENSORS Introducing Android Sensors Using the Sensor Manager Understanding the Android Sensors Discovering and Identifying Sensors Determining Sensor Capabilities Wakeup and Non-Wakeup Sensors Monitoring Sensor Results Interpreting Sensor Values Testing Sensors with the Android Virtual Device and Emulator Best Practices for Working with Sensors Monitoring a Device's Movement and Orientation Determining the Natural Orientation of a Device Introducing Accelerometers Detecting Acceleration Changes Creating a Gravitational Force Meter Determining a Device's Orientation Creating a Compass and Artificial Horizon xxvi 575 577 580 581 582 583 585 586 586 589 590 592 596 596 599 602 602 605 609 610 612 613 617 619 620 620 621 623 625 627 627 632 635 637 637 638 639 640 642 645 650 CONTENTS Using the EnvironmentalSensors Using the Barometer Sensor Creating a Weather Station Using Body Sensors User Activity Recognition CHAPTER 17: AUDIO, VIDEO, AND USING THE CAMERA Playing Audio and Video, and Using the Camera Playing Audio and Video Introducing the Media Player Using Media Player for Video Playback Using ExoPlayer for Video Playback Requesting and Managing Audio Focus Pausing Playback When the Output Changes Responding to the Volume Controls Working with a Media Session Using the Media Router and Cast Application Framework Background Audio Playback Building an Audio Playback Service Using a Media Browser to Connect Your Activity to a Media Browser Service Life Cycle of a Media Browser Service Playing Audio as a Foreground Service Creating Media Style Notifications 654 654 655 659 662 665 666 666 667 669 672 674 676 677 678 682 686 686 688 690 691 693 Using the Media Recorder to Record Audio Using the Camera for Taking Pictures 695 697 Recording Video 706 Using Intents to Take Pictures Controlling the Camera Directly Reading and Writing JPEG EXIF Image Details Using Intents to Record Video Using the Media Recorder to Record Video Adding Media to the Media Store Inserting Media Using the Media Scanner Inserting Media Manually CHAPTER 18: COMMUNICATING WITH BLUETOOTH, NFC, AND WI-Fl PEER-TO-PEER Networking and Peer-to-Peer Communication Transferring Data Using Bluetooth Managing the Local Bluetooth Device Adapter Being Discoverable and Remote Device Discovery 697 699 706 707 707 710 710 711 713 713 714 714 716 xxvii CONTENTS Bluetooth Communications Bluetooth Profiles Bluetooth Low Energy Transferring Data Using Wi-Fi Peer-to-Peer 728 Initializing the Wi-Fi Peer-to-Peer Framework Discovering Peers Connecting with Peers Transferring Data Between Peers 729 Using Near Field Communication Reading NFC Tags Using the Foreground Dispatch System Using Android Beam Creating Android Beam Messages Assigning the Android Beam Payload Receiving Android Beam Messages CHAPTER 19: INVADING THE HOME SCREEN Customizing the Home Screen Introducing Home Screen Widgets Defining the Widget Layout Defining Your Widget Size and Other Metadata Implementing Your Widget Updating the Widget UI Using the App Widget Manager and Remote Views Forcing Refreshes of Your Widget Data and UI Creating and Using a Widget Configuration Activity Creating an Earthquake Widget Introducing Collection View Widgets Creating Collection View Widget Layouts Updating Collection View Items with a Remote Views Factory Updating Collection View Items with a Remote Views Service Populating Collection View Widgets Using a Remote Views Service Adding Interactivity to the Items Within a Collection View Widget Refreshing Your Collection View Widgets Creating an Earthquake Collection View Widget Creating Live Wallpaper Creating a Live Wallpaper Definition Resource Creating a Wallpaper Service Engine Creating a Wallpaper Service xxviii 720 725 726 731 732 733 735 735 736 738 739 740 742 743 743 744 745 746 748 749 753 756 757 763 764 765 767 768 769 770 770 777 778 778 780 CONTENTS Creating App Shortcuts Static Shortcuts Dynamic Shortcuts Tracking App Shortcut Use CHAPTER 20: ADVANCED ANDROID DEVELOPMENT Advanced Android Paranoid Android Linux Kernel Security Re-introducing Permissions Storing Keys in the Android Keystore Using the Fingerprint Sensor Dealing with Different Hardware and Software Availability Specifying Required Hardware Confirming Hardware Availability Building Backward-Compatible Applications Optimizing UI Performance with Strict Mode Telephony and SMS Telephony Sending and Receiving SMS Messages CHAPTER 21: RELEASING, DISTRIBUTING, AND MONITORING APPLICATIONS 781 783 784 785 787 788 788 788 789 792 792 793 794 795 795 797 798 799 806 825 Preparing for Release 826 Updating Application Metadata in Your Application Manifest 828 Signing Production Builds of Your Application 830 Distributing Your Application on the Google Play Store 835 Preparing Release Support Material Preparing Your Code for a Release Build Reviewing Application Installation Restrictions Application Versioning Creating a Keystore and Signing Key with Android Studio Obtaining API Keys Based on Your Private Release Key Building and Signing a Production Release Introducing the Google Play Store Getting Started with the Google Play Store Creating an Application on the Google Play Store Publishing Your Application Monitoring Your Application in Production 826 827 828 830 832 833 834 835 836 837 845 848 xxix INTRODUCTION For many people, smartphones have become an extension of themselves.Now running on over billion monthly-active devices, Android is the most common smartphone operating system in use world-wide, with users installing an average of 50 apps each, resulting in over 94 billion apps downloaded from the Play app store in 2017 alone Ubiquitous and indispensable, smartphones are so advanced and personal that studies have shown people become anxious if they misplace their device, lose connectivity, or run low on battery In the 1()years since launching in 2008, Android has expanded beyond mobile phones to become a development platform for a wide range of hardware, with 24,000 devices from over 1,300 brands, including everything from tablets to televisions,watches, cars, and Internet of Things (IOT)devices Over the same period, there have been 28 platform and SDKreleases These innovations, combined with the size of the ecosystem, provide unparalleled opportunities for developers to create innovative new applications for a global audience of users Android offers an open platform for mobile application development.Without artificial barriers, Android developers are free to write apps that take full advantage of an incrediblerange of devices.Using Google Play for distribution, developerscan distribute free and paid applications to compatible Android devices globally This book is a hands-on guide to building Android applications for all Android devices It's written based on version 8.1 of the Android SDK, using Android Studio 3.1 Chapter by chapter, it takes you through a series of sample projects, each introducing new features and techniques to get the most out of Android It covers all the basic functionality to get started, as well as the information for experienced mobile developers to take full advantage of the features of Android, to enhance existing products or create innovative new ones The Android team releases a new major platform every year, a new version of Android Studio every few months, and incremental changes to Jetpack, such as the support library and Android Architecture Components, many times each year With such rapid release cycles, there are regular changes', additions, and improvements to the tools, platform APIs, and development libraries you'll use—and which are described in this book To minimize the impact of these changes, the Android engineering team works hard to ensure backward compatibility However, future releases will date some of the information provided in this book, and not all active Android devices will be running the latest platform release To mitigate this, wherever possible, we have used backward-compatible support libraries, and included details on which platform releases support the functionality described—and which alternatives may exist to provide support for users of devices running earlier platforms Further, the explanations and examples included will give you the grounding and knowledge needed to write compelling mobile applications using the current SDK, along with the flexibility to quickly adapt to future enhancements INTRODUCTION WHO THIS BOOK IS FOR This book is for anyone interested in creating applicationsfor the Android platform It includes information that will be valuable, whether you're an experienced mobile developer on other platforms, making your first foray into writing mobile apps, and if you have some Android development experience It will help if you've used a smartphone (particularly an Android device), but it's not necessary, nor is prior experience in mobile application development It's expected that you'll have experience in software development and be familiar with basic objectoriented paradigms An understanding of Java syntax is expected, though not a strict necessity Chapters and introduce mobile developmentand the Android developmentplatform, and contain instructions to get you started Beyondthat, there's no requirementto read the chapters in order, although a good understanding of the core components described in Chapters 3—7is important before you venture into the remaining chapters Chapter 11 covers important details on how to ensure your apps are responsive and efficient, while Chapters 12—14describe how to provide a rich and consistent user experience The remaining chapters cover a variety of functionality whose relevance will vary based on your application, and can be read in whatever order interest or need dictates WHAT THIS BOOK COVERS Chapter introduces Android, including what it is and how it fits into the mobile development ecosystem What Android offers as a development platform and why it's an exciting opportunity for creating mobile phone applications are then examined in greater detail Chapter covers some best practices for mobile development and explains how to download and install Android Studio and the Android SDK It then introduces some of the tools and features included with Android Studio, and demonstrates how they can be used to create and debug new applications Chapters 3—7take an in-depth look at the fundamental Android application components-—starting by examining the components that make up an Android application, and then moving on to "Activities" and "Fragments," and their associated lifetimes and lifecycles You'll then be introduced to the application manifest and the Gradle build system, before learning more about the external resource framework used to support devices used in different counties, with different languages, and in a variety of shapes and sizes You'll learn how to create basic user interfaces with layouts, Views, and Fragments, before being introduced to the Intent and BroadcastReceivermechanismsused to perform actions and send messages between application components Accessing Internet resources is then covered, followed by a detailed look at data storage, retrieval, and sharing You'll start with the preference-saving xxxii INTRODUCTION mechanism and then move on to file handling, databases, and Content Providers—includingaccessing data from the native databases This section finishes with an examination of how to ensure your app is always responsive, and is efficient in its use of battery when running in the background You'll be introduced to threading APIs that enable asynchronous execution, and mechanisms that support efficient scheduling of background work You'll also learn how to create and display interactive Notifications Chapters 12—14build on the UI framework introduced in Chapter You'll learn to enhance the user experience through the principles of material design and to make your applications accessible and optimized for a variety of screen sizes and resolutions You'll further improve the user experience by understanding the variety of navigation options available,adding movement through animations, and the use of Toolbars and Menus Chapters 15—19look at more advanced topics You'll learn how to use Google Play services to add interactive maps, find the user's location, and how to create geo- and awareness-fences Using movement and environmental Sensors—includingthe compass, accelerometers,and the barometer— you'll make your applications react to their environment After looking at how to play and record multimedia, as well as how to use the camera to take pictures and record video, you'll be introduced to Android's communication capabilities, including Bluetooth, NFC, and Wi-Fi Direct Next, you'll learn how your applications can interact with users directly from the home screen using dynamic Widgets, LiveWallpaper,and the Application Shortcuts Chapter 20 discusses several advanced developmenttopics, including security, using the fingerprint sensor, and Strict Mode, followed by the telephony APIs and the APIs used to send and receive SMS messages Finally, Chapter 21 examines the process for building, releasing, monitoring, and monetizing your applications In particular, it includes details for publishing and distributing your applications within Google Play HOW THIS BOOK IS STRUCTURED This book is structured in a logical sequence to help readers of different development backgrounds learn how to write advanced Android applications There's no requirement to read each chapter sequentially, but several of the sample projects are developed over the course of multiple chapters, adding new functionality and other enhancements at each stage Experienced mobile developers who have already installed Android Studio, and those with a working knowledge of Android development, can skim the first two chapters—whichare an introduction to mobile development and instructions for creating your development environment—and then dive in at Chapters 3—7.These chapters cover the fundamentals of Android development, so it's important to have a solid understanding of the concepts they describe xxxiii INTRODUCTION design, maps, With this covered, you can move on to the remaining chapters, which look at material hardware as location-based services, background applications, and more advanced topics, such interaction and networking WHAT you NEED TO USE THIS BOOK To use the code samples in this book, you will need to create an Android development environment by downloading Android Studio and the Android SDK It's also possible to use other IDES, or even to build your apps from the command-line We'll assume, however, you're using Android Studio Android development is supported on Windows, macOS, and Linux, with Android Studio and the SDK available from the Android website You not need an Android device to use this book or develop Android applications—though it can be useful, particularly when testing NOTE Chapter outlines these requirements in more detail and describes where to download and how to install each component CONVENTIONS To help you get the most from the text and keep track of what's happening, we've used a number Of conventions throughout the book NOTE Notes, tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this WARNING Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text As for styles in the text: We show file names, URLs, and code within the text like so: persistence properties• class readability, names in text are often represented To help using a regular font but capitalProvider Content so: like ized xxxiv INTRODUCTION We present code in two different ways: We use a monofont type with no highlighting for most code examples We use bold to indicate changes or additions from a similar previous code snippet In some code samples, you'll see lines marked as follows: [ or Existing code Implement something here These represent instructions to replace the entire line (including the square brackets) with actual code, either from a previous code snippet (in the former case) or with your own implementation (in the latter) To keep the code samples reasonably concise, we have not always included every package definition or import statement required in the code snippets The downloadable code samples described below include all the required import statements Additionally, if you are developing using Android Studio, you can enable auto-import or use the keyboard shortcut Ctrl+Space(Cmd+Space)to add the required import statements SOURCE CODE As you work through the examples in this book, you may choose either to type in all the code manually, or to use the source code files that accompany the book All the source code used in this book is available for download at www.wrox.com.When at the site, simply locate the book's title (use the Search box or one of the title lists) and click the Download Code link on the book's detail page to obtain all the source code for the book Once you download the code, just decompress it with your favorite compression tool Alternately, you can go to the main Wrox code download page at www.wrox.com/dynamic/books/download aspx to see the code available for this book and all other Wrox books ERRATA the code However, no one We make every effort to ensure that there are no errors in the text or in books, like a spelling mistake is perfect, and mistakes occur If you find an error in one of our sending in errata, you may or faulty piece of code, we would be very grateful for your feedback By you will be helping us provide even save another reader hours of frustration, and at the same time, higher quality information and locate the title using the Search box To find the errata page for this book, go to www.wrox.com click the Book Errata link On this page, you or one of the title lists Then, on the book details page, posted by Wrox editors A complete can view all errata that has been submitted for this book and .. .PROFESSIONAL ANDROID@ ,FOURTH EDITION xxxi INTRODUCTION CHAPTER CHAPTER CHAPTER CHAPTER Hello, Android Getting... Development Releasing, Distributing, and Monitoring Applications 713 743 787 825 863 PROFESSIONAL Android@ Fourth Edition Reto Meier Ian Lake wrox A Wiley Brand CONTENTS INTRODUCTION CHAPTER 1: HELLO,... as the information for experienced mobile developers to take full advantage of the features of Android, to enhance existing products or create innovative new ones The Android team releases a

Ngày đăng: 22/10/2022, 13:23

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...