Tài liệu Android in Action pdf

662 1,584 0
  • Loading ...
1/662 trang
Tải xuống

Thông tin tài liệu

Ngày đăng: 17/02/2014, 08:20

MANNINGW. Frank AblesonRobi SenChris KingC. Enrique Ortiz THIRD EDITIONIN ACTIONwww.it-ebooks.infoAndroid in ActionThird Editionwww.it-ebooks.infowww.it-ebooks.infoAndroid in ActionThird EditionW. FRANK ABLESONROBI SENCHRIS KINGC. ENRIQUE ORTIZMANNINGSHELTER ISLANDwww.it-ebooks.infoFor online information and ordering of this and other Manning books, please visitwww.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contactSpecial Sales DepartmentManning Publications Co.20 Baldwin RoadPO Box 261Shelter Island, NY 11964Email: orders@manning.com©2012 by Manning Publications Co. All rights reserved.No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps.Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning booksare printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine.Manning Publications Co. Development editor: Troy Mott20 Baldwin Road Copyeditors: Benjamin Berg, Tiffany TaylorPO Box 261 Typesetter: Dottie MarsicoShelter Island, NY 11964 Cover designer: Marija TudorISBN 9781617290503Printed in the United States of America1 2 3 4 5 6 7 8 9 10 – MAL – 16 15 14 13 12 11www.it-ebooks.infovbrief contentsPART 1 WHAT IS ANDROID? THE BIG PICTURE 11■Introducing Android 32■Android’s development environment 33PART 2 EXERCISING THE ANDROID SDK 633■User interfaces 654■Intents and Services 1025■Storing and retrieving data 1306■Networking and web services 1607■Telephony 1888■Notifications and alarms 2069■Graphics and animation 22610■Multimedia 26011■Location, location, location 284PART 3 ANDROID APPLICATIONS 30912■Putting Android to work in a field service application 31113■Building Android applications in C 356www.it-ebooks.infoBRIEF CONTENTSviPART 4 THE MATURING PLATFORM 38314■Bluetooth and sensors 38515■Integration 40516■Android web development 43917■AppWidgets 47218■Localization 50919■Android Native Development Kit 52420■Activity fragments 54521■Android 3.0 action bar 56022■Drag-and-drop 579www.it-ebooks.infoviicontentspreface xixacknowledgments xxiabout this book xxiiiabout the cover illustration xxviiiPART 1 WHAT IS ANDROID? THE BIG PICTURE 11 Introducing Android 31.1 The Android platform 41.2 Understanding the Android market 5Mobile operators 5■Android vs. the feature phones 6Android vs. the smartphones 7■Android vs. itself 8Licensing Android 91.3 The layers of Android 10Building on the Linux kernel 11■Running in the Dalvik VM 121.4 The Intent of Android development 13Empowering intuitive UIs 13■Intents and how they work 141.5 Four kinds of Android components 17Activity 17■Service 18■BroadcastReceiver 19ContentProvider 22www.it-ebooks.infoCONTENTSviii1.6 Understanding the AndroidManifest.xml file 241.7 Mapping applications to processes 261.8 Creating an Android application 261.9 Android 3.0 for tablets and smartphones 30Why develop for Android tablets? 30■What’s new in the Android 3.0 Honeycomb platform? 311.10 Summary 322 Android’s development environment 332.1 Introducing the Android SDK 34Core Android packages 35■Optional packages 362.2 Exploring the development environment 36The Java perspective 37■The DDMS perspective 39Command-line tools 422.3 Building an Android application in Eclipse 45The Android Project Wizard 45■Android sample application code 46■Packaging the application 522.4 Using the Android emulator 53Setting up the emulated environment 54■Testing your application in the emulator 582.5 Debugging your application 592.6 Summary 61PART 2 EXERCISING THE ANDROID SDK 633 User interfaces 653.1 Creating the Activity 66Creating an Activity class 68■XML vs. programmatic layouts 69■Exploring the Activity lifecycle 72■The server connection 733.2 Working with views 75Exploring common views 76■Using a ListView 78Multitasking with Handler and Message 82■Creating custom views 83■Understanding layout 86■Handling focus 88Grasping events 89www.it-ebooks.infoCONTENTS ix3.3 Using resources 90Supported resource types 90■Referencing resources in Java 91■Defining views and layouts through XML resources 93■Externalizing values 95■Providing animations 983.4 Exploring the AndroidManifest file 993.5 Summary 1014 Intents and Services 1024.1 Serving up RestaurantFinder with Intent 103Defining Intents 103■Implicit and explicit invocation 104Adding external links to RestaurantFinder 105■Finding your way with Intent 107■Taking advantage of Android-provided activities 1094.2 Checking the weather with a custom URI 110Offering a custom URI 110■Inspecting a custom URI 1124.3 Checking the weather with broadcast receivers 114Broadcasting Intent 114■Creating a receiver 1154.4 Building a background weather service 1164.5 Communicating with the WeatherAlertService from other apps 120Android Interface Definition Language 120■Binder and Parcelable 122■Exposing a remote interface 123Binding to a Service 124■Starting vs. binding 127Service lifecycle 1284.6 Summary 1295 Storing and retrieving data 1305.1 Using preferences 131Working with SharedPreferences 131■Preference access permissions 1345.2 Using the filesystem 137Creating files 137■Accessing files 138■Files as raw resources 139■XML file resources 140■External storage via an SD card 1425.3 Persisting data to a database 145Building and accessing a database 146■Using the sqlite3 tool 150www.it-ebooks.info[...]... Authenticating to LinkedIn Synchronizing to the backend with SyncAdapter The synchronizing lifecycle data 432 15.7 432 16 ■ 425 432 Synchronizing LinkedIn Wrapping up: LinkedIn in action 435 Finalizing the LinkedIn project Moving on 437 15.8 Telling ■ Summary 435 ■ Troubleshooting tips 436 437 Android web development 439 16.1 What’s Android web development? 440 Introducing WebKit options 441 16.2 440 ■ Examining... ■ Examining the architectural Optimizing web applications for Android 442 Designing with mobile in mind 442 Adding the viewport tag 444 Selectively loading content 446 Interrogating the user agent 446 The media query 447 Considering a madefor-mobile application 448 ■ ■ ■ ■ 16.3 ■ Storing data directly in the browser 449 Setting things up 450 Examining the code 451 The user interface 451 Opening the... Obtaining phone state Interacting with the phone 196 Using Intents to make calls 196 Using phone number–related utilities 198 Intercepting outbound calls 200 ■ ■ 7.5 Working with messaging: SMS 200 Sending SMS messages 7.6 8 Summary ■ Receiving SMS messages 205 Notifications and alarms 8.1 201 Introducing Toast 206 207 www.it-ebooks.info 204 xi CONTENTS 8.2 8.3 8.4 Placing your Toast message 209 Making... Looking at the NDK 526 527 Demonstrating the completed application project structure 529 19.3 Building an application with the NDK ■ Building the JNI library 528 Examining the 530 Understanding JNI 530 Implementing the library Compiling the JNI library 536 ■ 19.4 Building the user interface User interface layout edges 541 19.5 19.6 20 ■ 537 Taking a photo 539 ■ Finding the Integrating the NDK into... virtual machine (VM) Java programming skills are helpful throughout the book, but this chapter is more about setting the stage than about coding specifics One coding element introduced in this chapter is the Intent class Having a good understanding of and comfort level with the Intent class is essential for working with the Android platform In addition to Intent, this chapter introduces the four main application... xiv CONTENTS 15.2 15.3 Getting started with LinkedIn 411 Managing contacts 413 Leveraging the built -in Contacts app 413 Requesting operations from your app 416 Directly reading and modifying the contacts database 417 Adding contacts 418 ■ ■ ■ 15.4 Keeping it together 421 The dream of sync 421 Defining accounts secrets: The AccountManager service 423 422 ■ 15.5 Creating a LinkedIn account 424 Not friendly... Starting drag operations 586 Listening for drag-and-drop events 587 Responding to drag-start operations 588 Handling drop operations 589 Summary 590 Installing the Android SDK 591 Publishing applications 601 index 613 www.it-ebooks.info 575 574 www.it-ebooks.info preface The idea of a writing a book about Android development can be somewhat futile at times, considering the pace at which Android continues... www.it-ebooks.info ABOUT THIS BOOK xxv classes This chapter begins combining fundamental concepts with more real-world details, such as handling application state, using a database for persistent storage, and working with SQLite Chapter 6 deals with storing and retrieving data over the network Here we include a networking primer before delving into using raw networking concepts such as sockets on Android. .. demonstrates integrating with an external data source In particular, this application brings Android into the social-networking scene by integrating with the popular LinkedIn professional networking service Chapter 16 explores the world of web development Android s browser is based on the open source WebKit engine and brings desktop-like capability to this mobile browser This chapter equips you to bring attractive... the first edition, Unlocking Android, have been reused in the second and third editions of the book Although the title was changed to Android in Action during the writing of the second edition, we kept the original book title in our graphics and sample applications Author Online Purchase of Android in Action, Third Edition includes free access to a private web forum run by Manning Publications where . synchronizing lifecycle 432■Synchronizing LinkedIn data 43215.7 Wrapping up: LinkedIn in action 435Finalizing the LinkedIn project 435■Troubleshooting. Intents and Services 1024.1 Serving up RestaurantFinder with Intent 103Defining Intents 103■Implicit and explicit invocation 104Adding external links
- Xem thêm -

Xem thêm: Tài liệu Android in Action pdf, Tài liệu Android in Action pdf, Tài liệu Android in Action pdf, 3 What time is it? The DayTime Server, 1 What’s Android web development?, 5 Removing, showing, and hiding the action bar

Mục lục

Xem thêm

Gợi ý tài liệu liên quan cho bạn