Tải bản đầy đủ

406 professional android 2 application development

www.it-ebooks.info
Meier

Written by an Android authority, this up-to-date resource shows you
how to leverage the features of Android 2 to enhance existing
products or create innovative new ones. Serving as a hands-on guide
to building mobile apps using Android, the book walks you through
a series of sample projects that introduces you to Android’s new features
and techniques. Using the explanations and examples included in
these pages, you’ll acquire the foundation needed to write compelling
mobile applications that use Android, along with the flexibility to
quickly adapt to future enhancements.
Professional Android 2 Application Development:
• Reviews Android as a development platform and best practices
for mobile development
• Details creating layouts and Views to produce compelling resolution
independent user interfaces
• Examines Intents and Content Providers for sharing data
• Introduces techniques for creating map-based applications and using
location-based services such as GPS
• Looks at how to create and use background Services, Notifications,

and Alarms

Programmer
Forums
Join our Programmer to
Programmer forums to ask
and answer programming
questions about this book,
join discussions on the
hottest topics in the industry,
and connect with fellow
programmers from around
the world.

Code Downloads

• Explores the Bluetooth, telephony, and networking APIs

Take advantage of free code
samples from this book, as
well as code samples from
hundreds of other books, all
ready to use.

• Examines using hardware, including the camera and sensors such
as the compass and accelerometers

Read More

• Demonstrates how to create interactive homescreen components

Reto Meier is a software developer who has been involved in Android since the
initial release in 2007. He is an Android Developer Advocate at Google.
Wrox Professional guides are planned and written by working programmers
to meet the real-world needs of programmers, developers, and IT professionals.
Focused and relevant, they address the issues technology professionals face every
day. They provide examples, practical solutions, and expert education in new
technologies, all designed to help programmers do a better job.

Programming / Mobile & Wireless / Android



$44.99 USA
$53.99 CAN

Find articles, ebooks, sample
chapters and tables of contents
for hundreds of books, and
more reference resources on
programming topics that matter
to you.

Join the discussion @ p2p.wrox.com

Wrox Programmer to Programmer™



• Provides an in-depth look at the Android application components

wrox.com

Professional Android 2 Application Development

Build unique mobile applications
with the latest Android SDK

Professional


Android 2

Application Development
Reto Meier


www.it-ebooks.info

Related Wrox Books
Beginning iPhone SDK Programming with Objective-C

Programmer to Programmer™

Get more out of
wrox.com
Interact

Join the Community

Take an active role online by participating in our
P2P forums @ p2p.wrox.com

Sign up for our free monthly newsletter at
newsletter.wrox.com

Wrox Online Library

Browse

Hundreds of our books are available online
through Books24x7.com

Ready for more Wrox? We have books and
e-books available on .NET, SQL Server, Java,
XML, Visual Basic, C#/ C++, and much more!

Wrox Blox
Download short informational pieces and code
to keep you up to date and out of trouble!

Contact Us.
We always like to get feedback from our readers. Have a book idea?
Need community support? Let us know by e-mailing wrox-partnerwithus@wrox.com

ISBN: 9780470500972
Learning to develop iPhone applications doesn’t need to be an overwhelming undertaking. This book provides an easy-to-follow,
example-driven introduction to the fundamentals of the Apple iPhone SDK and offers you a clear understanding of how things
are done when programming iPhone applications with Objective-C. When you reach the end of the book, you will be prepared to
confidently tackle your next iPhone programming challenge.

Ivor Horton’s Beginning Java 2: JDK 5 Edition
ISBN: 978-0-7645-6874-9
This comprehensive introduction to Java programming — written by the leading author of computer programming language
tutorials — shows readers how to build real-world Java applications using the Java SDK (software development kit).

Safari and WebKit Development for iPhone OS 3.0
ISBN: 9780470549667
With the unparalleled success of iPhone and iPod touch, iPhone OS 3.0 has emerged as a compelling platform for which vast
numbers of web developers are designing and building web-based mobile applications. This book explores the Safari and WebKit
development platform that is built into iPhone OS 3.0 and takes you through the process of creating an iPhone web application
from the ground up. You’ll learn how to use existing open source frameworks to speed up your development time, imitate qualities
of built-in Apple apps, cache data locally and even run in offline mode, and more. Whether you’re eager to build new web applications
for iPhone OS 3.0 or optimize existing web sites for this platform, you have everything you need to do so within this book.


www.it-ebooks.info

PROFESSIONAL
ANDROID™ 2 APPLICATION DEVELOPMENT
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii
CHAPTER 1

Hello, Android . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

CHAPTER 2

Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

CHAPTER 3

Creating Applications and Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

CHAPTER 4

Creating User Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

CHAPTER 5

Intents, Broadcast Receivers, Adapters,
and the Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137

CHAPTER 6

Files, Saving State, and Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

CHAPTER 7

Databases and Content Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209

CHAPTER 8

Maps, Geocoding, and Location-Based Services . . . . . . . . . . . . . . . . . 245

CHAPTER 9

Working in the Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285

CHAPTER 10

Invading the Phone-Top . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327

CHAPTER 11

Audio, Video, and Using the Camera . . . . . . . . . . . . . . . . . . . . . . . . . . . 363

CHAPTER 12

Telephony and SMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389

CHAPTER 13

Bluetooth, Networks, and Wi-Fi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425

CHAPTER 14

Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457

CHAPTER 15

Advanced Android Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477

INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529


www.it-ebooks.info


www.it-ebooks.info

PROFESSIONAL

Android™ 2 Application Development
Reto Meier

Wiley Publishing, Inc.


www.it-ebooks.info

Professional Android™ 2 Application Development
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256

www.wiley.com
Copyright © 2010 by Wiley Publishing, Inc., Indianapolis, Indiana
ISBN: 978-0-470-56552-0
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 promotional 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 publisher 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 also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in
electronic books.
Library of Congress Control Number: 2009943638
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are
trademarks 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 trademark of Google, Inc. All other trademarks are the property
of their respective owners. Wiley Publishing, Inc. is not associated with any product or vendor mentioned in this book.


www.it-ebooks.info

To Kristy


www.it-ebooks.info


www.it-ebooks.info

ABOUT THE AUTHOR

RETO MEIER is originally from Perth, Western Australia, but now lives in London.

He currently works as an Android Developer Advocate at Google, helping Android app developers create the best applications possible. Reto is an experienced software developer with more than
10 years of experience in GUI application development. Before Google, he worked in various industries, including offshore oil and gas and finance.
Always interested in emerging technologies, Reto has been involved in Android since the initial
release in 2007. In his spare time, he tinkers with a wide range of development platforms, including
Google’s plethora of developer tools.
You can check out Reto’s web site, The Radioactive Yak, athttp://blog.radioactiveyak.com or
follow him on twitter at http://www.twitter.com/retomeier.

ABOUT THE TECHNICAL EDITOR

MILAN NARENDRA SHAH graduated with a BSc Computer Science degree from the University of
Southampton. He has been working as a software engineer for more than seven years, with
experiences in C#, C/C++, and Java. He is married and lives in Buckinghamshire, United Kingdom.


www.it-ebooks.info


www.it-ebooks.info

CREDITS

ACQUISITIONS EDITOR

Scott Meyers

VICE PRESIDENT AND EXECUTIVE GROUP
PUBLISHER

Richard Swadley
PROJECT EDITOR

William Bridges

VICE PRESIDENT AND EXECUTIVE PUBLISHER

Barry Pruett
TECHNICAL EDITOR

Milan Narendra Shah

ASSOCIATE PUBLISHER

Jim Minatel
PRODUCTION EDITOR

Rebecca Anderson

PROJECT COORDINATOR, COVER

Lynsey Stanford
COPY EDITOR

Sadie Kleinman

PROOFREADER

Kyle Schlesinger, Word One
EDITORIAL DIRECTOR

Robyn B. Siesky

INDEXER

Robert Swanson
EDITORIAL MANAGER

Mary Beth Wakefield

COVER IMAGE

© Linda Bucklin/istockphoto
ASSOCIATE DIRECTOR OF MARKETING

David Mayhew

COVER DESIGNER

Michael E. Trent
PRODUCTION MANAGER

Tim Tate


www.it-ebooks.info


www.it-ebooks.info

ACKNOWLEDGMENTS

Most importantly I’d like to thank Kristy. Your support makes everything I do possible, and your
generous help ensured that this book was the best it could be. Without you it would never have
happened.
A big thank-you goes to Google and the Android team, particularly the Android engineers and my
colleagues in developer relations. The pace at which Android has grown and developed in the past
year is nothing short of phenomenal.
I also thank Scott Meyers for giving me the chance to bring this book up to date; and Bill Bridges,
Milan Shah, Sadie Kleinman, and the Wrox team for helping get it done.
Special thanks go out to the Android developer community. Your hard work and exciting applications have helped make Android a great success.


www.it-ebooks.info


www.it-ebooks.info

CONTENTS

INTRODUCTION
CHAPTER 1: HELLO, ANDROID

A Little Background
The Not-So-Distant Past
The Future

What It Isn’t
Android: An Open Platform for Mobile Development
Native Android Applications
Android SDK Features
Access to Hardware, Including Camera, GPS, and Accelerometer
Native Google Maps, Geocoding, and Location-Based Services
Background Services
SQLite Database for Data Storage and Retrieval
Shared Data and Interapplication Communication
Using Widgets, Live Folders, and Live Wallpaper to Enhance the
Home Screen
Extensive Media Support and 2D/3D Graphics
Optimized Memory and Process Management

Introducing the Open Handset Alliance
What Does Android Run On?
Why Develop for Mobile?
Why Develop for Android?
What Has and Will Continue to Drive Android Adoption?
What Does It Have That Others Don’t?
Changing the Mobile Development Landscape

xxvii
1

2
2
3

3
4
5
6
6
7
7
7
7
8
8
8

9
9
9
10
10
11
11

Introducing the Development Framework

12

What Comes in the Box
Understanding the Android Software Stack
The Dalvik Virtual Machine
Android Application Architecture
Android Libraries

12
13
14
15
16

Summary

16


www.it-ebooks.info
CONTENTS

CHAPTER 2: GETTING STARTED

Developing for Android
What You Need to Begin
Downloading and Installing the SDK
Developing with Eclipse
Using the Eclipse Plug-In
Creating Your First Android Application
Starting a New Android Project
Creating a Launch Configuration
Running and Debugging Your Android Applications
Understanding Hello World
Types of Android Applications
Foreground Applications
Background Services and Intent Receivers
Intermittent Applications
Widgets

Developing for Mobile Devices
Hardware-Imposed Design Considerations
Be Efficient
Expect Limited Capacity
Design for Small Screens
Expect Low Speeds, High Latency
At What Cost?
Considering the Users’ Environment
Developing for Android
Being Fast and Efficient
Being Responsive
Developing Secure Applications
Ensuring a Seamless User Experience

To-Do List Example
Android Development Tools
The Android Virtual Device and SDK Manager
Android Virtual Devices
SDK Manager
The Android Emulator
Dalvik Debug Monitor Service (DDMS)
The Android Debug Bridge (ADB)

Summary

xiv

17

18
18
18
19
20
23
23
24
26
26
29
29
29
30
30

30
30
31
31
32
32
33
34
35
35
36
37
37

38
43
44
44
45
46
47
47

48


www.it-ebooks.info
CONTENTS

CHAPTER 3: CREATING APPLICATIONS AND ACTIVITIES

What Makes an Android Application?
Introducing the Application Manifest
Using the Manifest Editor
The Android Application Life Cycle
Understanding Application Priority and Process States
Externalizing Resources
Creating Resources
Creating Simple Values
Styles and Themes
Drawables
Layouts
Animations
Menus
Using Resources
Using Resources in Code
Referencing Resources within Resources
Using System Resources
Referring to Styles in the Current Theme
To-Do List Resources Example
Creating Resources for Different Languages and Hardware
Runtime Configuration Changes

49

50
51
56
57
58
59
60
60
62
63
63
64
66
67
67
68
69
70
70
71
72

Introducing the Android Application Class

74

Extending and Using the Application Class
Overriding the Application Life Cycle Events

74
75

A Closer Look at Android Activities
Creating an Activity
The Activity Life Cycle
Activity Stacks
Activity States
Monitoring State Changes
Understanding Activity Lifetimes
Android Activity Classes

Summary
CHAPTER 4: CREATING USER INTERFACES

Fundamental Android UI Design
Introducing Views

76
77
78
78
79
80
82
84

84
85

86
86

xv


www.it-ebooks.info
CONTENTS

Creating Activity User Interfaces with Views
The Android Widget Toolbox

Introducing Layouts

89

Using Layouts
Optimizing Layouts

89
91

Creating New Views
Modifying Existing Views
Customizing Your To-Do List
Creating Compound Controls
Creating Custom Views
Creating a New Visual Interface
Handling User Interaction Events
Creating a Compass View Example
Using Custom Controls

Drawable Resources
Shapes, Colors, and Gradients
Color Drawable
Shape Drawable
Gradient Drawable
Composite Drawables
Transformative Drawables
Layer Drawable
State List Drawables
Level List Drawables
NinePatch Drawable

Resolution and Density Independence
The Resource Framework and Resolution Independence
Resource Qualifiers for Screen Size and Pixel Density
Specifying Supported Screen Sizes
Best Practices for Resolution Independence
Relative Layouts and Density-Independent Pixels
Using Scalable Graphics Assets
Provide Optimized Resources for Different Screens
Testing, Testing, Testing
Emulator Skins
Testing for Custom Resolutions and Screen Sizes

Creating and Using Menus
Introducing the Android Menu System
Defining an Activity Menu
Menu Item Options

xvi

87
88

91
92
93
96
99
99
104
105
110

111
111
111
111
113
114
114
116
116
116
117

117
118
118
119
119
120
120
121
121
122
122

123
123
124
126


www.it-ebooks.info
CONTENTS

Dynamically Updating Menu Items
Handling Menu Selections
Submenus and Context Menus
Creating Submenus
Using Context Menus
Defining Menus in XML
To-Do List Example Continued

Summary
CHAPTER 5: INTENTS, BROADCAST RECEIVERS, ADAPTERS,
AND THE INTERNET

Introducing Intents
Using Intents to Launch Activities
Explicitly Starting New Activities
Implicit Intents and Late Runtime Binding
Returning Results from Activities
Native Android Actions
Using Intent Filters to Service Implicit Intents
How Android Resolves Intent Filters
Finding and Using the Launch Intent Within an Activity
Passing on Responsibility
Select a Contact Example
Using Intent Filters for Plug-Ins and Extensibility
Supplying Anonymous Actions to Applications
Incorporating Anonymous Actions in Your Activity’s Menu
Introducing Linkify
The Native Linkify Link Types
Creating Custom Link Strings
Using the Match Filter
Using the Transform Filter
Using Intents to Broadcast Events
Broadcasting Events with Intents
Listening for Broadcasts with Broadcast Receivers
Broadcasting Sticky and Ordered Intents
Native Android Broadcast Actions

Introducing Pending Intents
Introducing Adapters
Introducing Some Native Adapters
Customizing the Array Adapter
Using Adapters for Data Binding

127
127
128
128
128
130
131

136

137

138
138
139
139
140
143
144
146
147
147
148
152
153
154
155
155
156
157
157
157
158
158
161
161

162
163
163
163
164
xvii


www.it-ebooks.info
CONTENTS

Customizing the To-Do List Array Adapter
Using the Simple Cursor Adapter

Using Internet Resources
Connecting to an Internet Resource
Using Internet Resources

Introducing Dialogs
Introducing the Dialog Classes
The Alert Dialog Class
Specialist Input Dialogs
Using Activities as Dialogs
Managing and Displaying Dialogs

Creating an Earthquake Viewer
Summary
CHAPTER 6: FILES, SAVING STATE, AND PREFERENCES

Saving Simple Application Data
Creating and Saving Preferences
Retrieving Shared Preferences
Creating a Settings Activity for the Earthquake Viewer
Introducing the Preference Activity and Preferences Framework
Defining a Preference Screen Layout in XML
Native Preference Controls
Using Intents to Import System Preference Screens
Introducing the Preference Activity
Finding and Using Preference Screen Shared Preferences
Introducing Shared Preference Change Listeners

Creating a Standard Preference Activity for the Earthquake Viewer
Saving Activity State

170
170
171

172
172
173
174
174
175

176
184
187

188
188
189
189
197
198
199
200
200
201
201

202
203

Saving and Restoring Instance State
Saving the To-Do List Activity State

203
205

Saving and Loading Files
Including Static Files as Resources
File Management Tools
Summary

207
207
208
208

CHAPTER 7: DATABASES AND CONTENT PROVIDERS

xviii

165
169

209

Introducing Android Databases

209

Introducing SQLite Databases
Introducing Content Providers

210
210


www.it-ebooks.info
CONTENTS

Introducing SQLite
Cursors and Content Values
Working with SQLite Databases
Introducing the SQLiteOpenHelper
Opening and Creating Databases without SQLiteHelper
Android Database Design Considerations
Querying a Database
Extracting Results from a Cursor
Adding, Updating, and Removing Rows
Inserting New Rows
Updating a Row
Deleting Rows
Saving Your To-Do List

Creating a New Content Provider
Exposing Access to the Data Source
Registering Your Provider

Using Content Providers
Introducing Content Resolvers
Querying for Content
Adding, Updating, and Deleting Content
Inserts
Deletes
Updates
Accessing Files in Content Providers

Creating and Using an Earthquake Content Provider
Creating the Content Provider
Using the Provider

Native Android Content Providers
Using the Media Store Provider
Using the Contacts Provider
Introducing the Contacts Contract Content Provider
Reading Contact Details
Modifying and Augmenting Contact Details

Summary
CHAPTER 8: MAPS, GEOCODING, AND LOCATION-BASED SERVICES

Using Location-Based Services
Configuring the Emulator to Test Location-Based Services
Updating Locations in Emulator Location Providers

210
211
211
214
215
215
215
216
217
217
218
218
218

224
225
227

227
227
228
228
228
229
229
230

230
230
236

238
239
240
240
240
243

244
245

246
246
246
xix


www.it-ebooks.info
CONTENTS

Selecting a Location Provider
Finding the Available Providers
Finding Location Providers Using Criteria

Finding Your Location
‘Where Am I?’ Example
Tracking Movement
Updating Your Location in ‘Where Am I?’

Using Proximity Alerts
Using the Geocoder
Reverse Geocoding
Forward Geocoding
Geocoding ‘Where Am I?’

Creating Map-Based Activities
Introducing Map View and Map Activity
Getting Your Maps API Key
Getting Your Development/Debugging MD5 Fingerprint
Getting your Production/Release MD5 Fingerprint
Creating a Map-Based Activity
Configuring and Using Map Views
Using the Map Controller
Mapping ‘Where Am I?’
Creating and Using Overlays
Creating New Overlays
Introducing Projections
Drawing on the Overlay Canvas
Handling Map Tap Events
Adding and Removing Overlays
Annotating ‘Where Am I?’
Introducing My Location Overlay
Introducing Itemized Overlays and Overlay Items
Pinning Views to the Map and Map Positions

Mapping Earthquakes Example
Summary
CHAPTER 9: WORKING IN THE BACKGROUND

Introducing Services
Creating and Controlling Services
Creating a Service
Registering a Service in the Manifest
Self-Terminating a Service
xx

247
248
248

249
250
252
253

255
256
257
258
259

260
260
261
261
262
262
263
264
265
268
268
269
269
270
271
271
275
275
278

279
284
285

286
287
287
289
289


www.it-ebooks.info
CONTENTS

Starting, Controlling, and Interacting with a Service
An Earthquake Monitoring Service Example
Binding Activities to Services
Prioritizing Background Services

Using Background Threads
Using AsyncTask to Run Asynchronous Tasks
Creating a New Asynchronous Task
Running an Asynchronous Task
Moving the Earthquake Service to a Background Thread Using AsyncTask
Manual Thread Creation and GUI Thread Synchronization
Creating a New Thread
Using the Handler for Performing GUI Operations

Let’s Make a Toast
Customizing Toasts
Using Toasts in Worker Threads

Introducing Notifications
Introducing the Notification Manager
Creating Notifications
Creating a Notification and Configuring the Status Bar Icon
Configuring the Extended Status Notification Display
Triggering Notifications
Adding Notifications and Toasts to the Earthquake Monitor
Advanced Notification Techniques
Using the Defaults
Making Sounds
Vibrating the Phone
Flashing the Lights
Ongoing and Insistent Notifications

Using Alarms
Setting Repeating Alarms
Using Repeating Alarms to Update Earthquakes

Summary

290
290
297
299

300
301
301
302
303
304
304
304

306
306
308

309
310
310
310
311
313
314
316
317
317
317
318
319

320
322
323

325

CHAPTER 10: INVADING THE PHONE-TOP

327

Introducing Home-Screen Widgets
Creating App Widgets

328
328

Creating the Widget Layout
Widget Design Guidelines
Supported Widget Views and Layouts
Defining Your Widget Settings

329
329
330
331
xxi


www.it-ebooks.info
CONTENTS

Creating Your Widget Intent Receiver and Adding It to the
Application Manifest
Introducing Remote Views and the App Widget Manager
Creating Remote Views and Using the App Widget Manager
to Apply Them
Using a Remote View within the App Widget Provider’s
onUpdate Handler
Using Remote Views to Modify UI
Making Your Widgets Interactive
Refreshing Your Widgets
Using the Minimum Update Rate
Listening for Intents
Using Alarms
Creating and Using a Widget Configuration Activity

Creating an Earthquake Widget
Introducing Live Folders
Creating Live Folders
Live Folder Content Providers
Live Folder Activity
Creating an Earthquake Live Folder

Adding Search to Your Applications and the Quick Search Box
Adding Search to Your Application
Creating a Search Activity
Responding to Search Queries from a Content Provider
Surfacing Search Results to the Quick Search Box
Adding Search to the Earthquake Example

Creating Live Wallpaper
Creating a Live Wallpaper Definition Resource
Creating a Wallpaper Service
Creating a Wallpaper Service Engine

Summary
CHAPTER 11: AUDIO, VIDEO, AND USING THE CAMERA

Playing Audio and Video
Introducing the Media Player
Preparing Audio for Playback
Packaging Audio as an Application Resource
Initializing Audio Content for Playback
Preparing for Video Playback
Playing Video Using the Video View
xxii

332
333
333
334
335
335
337
337
338
339
340

341
346
346
347
348
349

351
351
352
353
355
355

358
359
359
360

361
363

364
364
365
365
365
366
367


www.it-ebooks.info
CONTENTS

Setting up a Surface for Video Playback
Initializing Video Content for Playback
Controlling Playback
Managing Media Playback Output

Recording Audio and Video
Using Intents to Record Video
Using the Media Recorder
Configuring and Controlling Video Recording
Previewing Video Recording

Using the Camera and Taking Pictures
Using Intents to Take Pictures
Controlling the Camera and Taking Pictures
Controlling and Monitoring Camera Settings and Image Options
Monitoring Auto Focus
Using the Camera Preview
Taking a Picture
Reading and Writing JPEG EXIF Image Details

Adding New Media to the Media Store
Using the Media Scanner
Inserting Media into the Media Store

Raw Audio Manipulation
Recording Sound with Audio Record
Playing Sound with Audio Track

Speech Recognition
Summary
CHAPTER 12: TELEPHONY AND SMS

Telephony
Launching the Dialer to Initiate Phone Calls
Replacing the Native Dialer
Accessing Phone and Network Properties and Status
Reading Phone Device Details
Reading Data Connection and Transfer State
Reading Network Details
Reading SIM Details
Monitoring Changes in Phone State, Phone Activity, and
Data Connections
Monitoring Incoming Phone Calls
Tracking Cell Location Changes
Tracking Service Changes
Monitoring Data Connectivity and Activity

367
369
370
370

371
371
372
373
374

375
375
377
377
379
379
381
381

382
382
383

384
384
385

386
388
389

390
390
390
392
392
392
393
394
395
396
396
397
398
xxiii


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay

×