android a programmer s guide dimarzio 2008 08 20 Lập trình android

326 38 0
android  a programmer s guide dimarzio 2008 08 20 Lập trình android

Đ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

Android ™ A Programmer’s Guide J.F DiMarzio New York Chicago San Francisco Lisbon London Madrid Mexico City Milan New Delhi San Juan Seoul Singapore Sydney Toronto CuuDuongThanCong.com Copyright © 2008 by The McGraw-Hill Companies All rights reserved Manufactured in the United States of America Except as permitted under the United States Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher 0-07-159989-4 The material in this eBook also appears in the print version of this title: 0-07-159988-6 All trademarks are trademarks of their respective owners Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the trademark Where such designations appear in this book, they have been printed with initial caps McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate training programs For more information, please contact George Hoare, Special Sales, at george_hoare@mcgraw-hill.com or (212) 904-4069 TERMS OF USE This is a copyrighted work and The McGraw-Hill Companies, Inc (“McGraw-Hill”) and its licensors reserve all rights in and to the work Use of this work is subject to these terms Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill’s prior consent You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited Your right to use the work may be terminated if you fail to comply with these terms THE WORK IS PROVIDED “AS IS.” McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE McGraw-Hill and its licensors not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation will be uninterrupted or error free Neither McGraw-Hill nor its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any damages resulting therefrom McGraw-Hill has no responsibility for the content of any information accessed through the work Under no circumstances shall McGraw-Hill and/or its licensors be liable for any indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of the possibility of such damages This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise DOI: 10.1036/0071599886 CuuDuongThanCong.com About the Author J.F DiMarzio is a developer with over 15 years of experience in networking and application development and is the author of seven books on computing technologies He has become a leading resource in the fields of IT consulting and development He lives in Central Florida About the Technical Editor Gilbert L Polo is a software developer with over 20 years of experience working in the telecommunications, financial, and, most recently, educational industries He has programmed in various languages including C, C++, Java, and C# Copyright © 2008 by The McGraw-Hill Companies Click here for terms of use CuuDuongThanCong.com Contents at a Glance What Is Android? Downloading and Installing Eclipse Downloading and Installing the Android SDK 21 35 Application: Hello World! 53 Using the Command-Line Tools and the Android Emulator 83 Exploring the Android SDK Using Intents and the Phone Dialer 117 Lists, Menus, and Other Views 149 Using the Cell Phone’s GPS Functionality 203 10 Using the Google API with GTalk 239 11 Application: Find a Friend 257 12 Android SDK Tool Reference 307 Index 313 vii CuuDuongThanCong.com For more information about this title, click here Contents ACKNOWLEDGMENTS INTRODUCTION xiii xv What Is Android? Brief History of Embedded Device Programming Open Handset Alliance and Android Introduction to Android Downloading and Installing Eclipse Why Eclipse? Downloading and Installing the JRE Downloading and Installing Eclipse Downloading and Installing the Android SDK Downloading the Android SDK Downloading and Installing the Android Plugin for Eclipse Configuring the Android Plugin for Eclipse ix CuuDuongThanCong.com 11 12 18 21 24 24 30 x Android: A Programmer’s Guide Exploring the Android SDK What Is in the Android SDK? Android Documentation Android Samples Try This: Run the API Demos Sample Application Android Tools APIs Application Life Cycle Standard ASP Application Life Cycle Android Application Life Cycle 35 Application: Hello World! Creating Your First Android Project in Eclipse Examining the Android-Created Files AndroidManifest.xml Referenced Libraries Directories Hello World! Again Hello World! Using an Image Hello World! Code-Based UI Hello World! XML-Based UI Try This: Use TextView and ImageView 53 37 38 39 41 45 48 49 49 50 55 61 62 62 63 69 72 75 78 81 Using the Command-Line Tools and the Android Emulator 83 Creating a Shell Activity Using the Windows CLI 84 Running the ActivityCreator.bat 85 The Project Structure 88 Creating the Hello World! Activity in the Windows CLI 95 Editing the Project Files 95 Adding the JAVA_HOME Variable 96 Compiling and Installing the Application 97 Hello World! on Linux 109 Configuring the PATH Statement 109 Try This: Create an Image-Based Hello World! in the CLI 115 Using Intents and the Phone Dialer What Are Intents? Using the Dialer Placing a Call from Your Activity Adding the Intent to Your Activity Editing Activity Permissions CuuDuongThanCong.com 117 119 124 128 129 131 Contents Modifying the AndroidPhoneDialer Adding a Button Implementing an EditText View Try This: Modify the AndroidPhoneDialer Project 136 136 141 145 Lists, Menus, and Other Views Building the Activities Intent Code for the xml File Intent Code for the java File Modifying the AndroidManifest.xml Using the Menu Creating the Activity for AutoComplete Button CheckBox EditText RadioGroup Spinner Try This: Modify More View Attributes 149 Using the Cell Phone’s GPS Functionality Using the Android Location-Based API Creating a kml File What Is a track File? Getting the nmea File in Windows Getting the nmea File in Linux Reading the GPS with the Android Location-Based API Creating the AndroidLBS Activity Passing Coordinates to Google Maps Adding Zoom Controls Try This: Toggling Between MapView’s Standard and Satellite Views 203 10 Using the Google API with GTalk Configuring the Android Emulator for GTalk Implementing GTalk in Android Creating the Activity’s Layout in the GoogleAPI.xml Adding Packages to GoogleAPI.java Implementing the View.OnClickListener Compiling and Running GoogleAPI Try This: Add a Settings Feature to Your GoogleAPI Activity 239 CuuDuongThanCong.com 151 152 154 155 157 163 173 178 183 189 195 202 204 205 208 208 210 212 212 222 226 232 241 244 245 247 248 252 255 xi xii Android: A Programmer’s Guide 11 Application: Find a Friend Creating a SQLite Database Creating a Custom Content Provider Editing the strings.xml Creating Your Content Provider Creating the FindAFriend Activity Editing AndroidManifest.xml Creating the NameEditor Activity Creating the LocationEditor Activity Creating the FriendsMap Activity Creating the FindAFriend Activity Running the FindAFriend Activity Try This: Real-Time Location Updating 257 259 263 263 265 276 276 278 283 293 299 302 305 12 Android SDK Tool Reference 307 Android Emulator Commands 308 Android Debug Bridge Commands 310 Index 313 CuuDuongThanCong.com Acknowledgments I would like to thank everyone who participated in the creation of this book My agent, Neil Salkind; Roger, Carly, Janet, Bill, and the crew at McGraw-Hill; Gil Polo; and everyone at Studio B I would also like to thank my family, Suzannah, Christian, and Sophia; Brett, Robert, Roger, Zack, Mark, Kurt, Walter, Walter, Walter, Steve, Steve, Steve, and Gary—and all my colleagues in Central Florida; and anyone else whom I may have forgotten xiii Copyright © 2008 by The McGraw-Hill Companies Click here for terms of use CuuDuongThanCong.com Introduction W elcome to Android: A Programmer’s Guide This book has been designed to give you the best first step toward the exciting new frontier of open source mobile development Android is the newest mobile device operating system, and this is one of the first books to help the average programmer become a fearless Android developer Through the course of this book, you will be introduced to the fundamentals of mobile device application development using the Open Handset Alliance’s Android platform By the end of this book, you will be able to confidently create your own mobile device programs The format of this book is such that it will take you through Android application development in a logical manner The book begins by examining the architecture of Android as a platform, looking at how it was developed, what it can run on, and what tools are required to develop programs for it After discussing and installing the development tools, Android SDK, and the Eclipse development environment (Chapters 2, 3, and 4), the book dives directly into designing and creating Android applications (Chapter 5) The book concludes with instructions on tying your applications to existing Google tools such as Google Maps (Chapters and 11) and GTalk (Chapter 10) A quick reference guide is also included in Chapter 12 This book is a programmer’s guide, not a beginner’s guide, meaning that you need to possess some programming skills to get the most from it Foremost among these skills is a working knowledge of Java programming fundamentals Android applications are xv Copyright © 2008 by The McGraw-Hill Companies Click here for terms of use CuuDuongThanCong.com ... the prior written permission of the publisher 0-0 7-1 5998 9-4 The material in this eBook also appears in the print version of this title: 0-0 7-1 5998 8-6 All trademarks are trademarks of their respective... Hoare, Special Sales, at george_hoare@mcgraw-hill.com or (212) 90 4-4 069 TERMS OF USE This is a copyrighted work and The McGraw-Hill Companies, Inc (“McGraw-Hill”) and its licensors reserve all rights... writing of this book, the latest Eclipse package file for Microsoft Windows is eclipse-java-europa-fall2-win32.zip Expand the package and run the eclipse.exe file Eclipse installs to your User

Ngày đăng: 29/08/2020, 14:56

Mục lục

  • Contents

  • Acknowledgments

  • Introduction

  • 1 What Is Android?

    • Brief History of Embedded Device Programming

    • Open Handset Alliance and Android

    • Introduction to Android

    • 2 Downloading and Installing Eclipse

      • Why Eclipse?

      • Downloading and Installing the JRE

      • Downloading and Installing Eclipse

      • 3 Downloading and Installing the Android SDK

        • Downloading the Android SDK

        • Downloading and Installing the Android Plugin for Eclipse

        • Configuring the Android Plugin for Eclipse

        • 4 Exploring the Android SDK

          • What Is in the Android SDK?

            • Android Documentation

            • Android Samples

            • Try This: Run the API Demos Sample Application

            • Android Tools

            • APIs

            • Application Life Cycle

              • Standard ASP Application Life Cycle

              • Android Application Life Cycle

              • 5 Application: Hello World!

                • Creating Your First Android Project in Eclipse

Tài liệu cùng người dùng

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

Tài liệu liên quan