android-a programmer's guide

1 What Is Android? . . . 1 Brief History of Embedded Device Programming . . . 2 Open Handset Alliance and Android . . 5 Introduction to Android . . 6 2 Downloading and Installing Eclipse . . 9 Why Eclipse? . . 11 Downloading and Installing the JRE . . 12 Downloading and Installing Eclipse . . 18 3 Downloading and Installing the Android SDK . . . 21 Downloading the Android SDK . . . 24 Downloading and Installing the Android Plugin for Eclipse . . 24 Configuring the Android Plugin for Eclipse . . 30 4 Exploring the Android SDK . . 35 What Is in the Android SDK? . . . 37 Android Documentation . . . 38 Android Samples . . 39 Try This: Run the API Demos Sample Application . . . 41 Android Tools . . 45 APIs . . 48 Application Life Cycle . . 49 Standard ASP Application Life Cycle . . 49 Android Application Life Cycle . . 50 5 Application: Hello World! . . 53 Creating Your First Android Project in Eclipse . . . 55 Examining the Android-Created Files . . . 61 AndroidManifest.xml . . . 62 Referenced Libraries . . . 62 Directories . . . 63 Hello World! Again . . . 69 Hello World! Using an Image . . . 72 Hello World! Code-Based UI . . 75 Hello World! XML-Based UI . . 78 Try This: Use TextView and ImageView . . . 81 6 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 7 Using Intents and the Phone Dialer . . . 117 What Are Intents? . . 119 Using the Dialer . . 124 Placing a Call from Your Activity . . 128 Adding the Intent to Your Activity . . 129 Editing Activity Permissions . . . 131 Modifying the AndroidPhoneDialer . . 136 Adding a Button . . . 136 Implementing an EditText View . . 141 Try This: Modify the AndroidPhoneDialer Project . . 145 8 Lists, Menus, and Other Views . . 149 Building the Activities . . . 151 Intent Code for the .xml File . . . 152 Intent Code for the .java File . . . 154 Modifying the AndroidManifest.xml . . . 155 Using the Menu . . 157 Creating the Activity for AutoComplete . . 163 Button . . . 173 CheckBox . . 178 EditText . . . 183 RadioGroup . . 189 Spinner . . 195 Try This: Modify More View Attributes . . 202 9 Using the Cell Phone’s GPS Functionality . . . 203 Using the Android Location-Based API . . . 204 Creating a kml File . . . 205 What Is a track File? . . . 208 Getting the nmea File in Windows . . 208 Getting the nmea File in Linux . . . 210 Reading the GPS with the Android Location-Based API . . 212 Creating the AndroidLBS Activity . . 212 Passing Coordinates to Google Maps . . 222 Adding Zoom Controls . . . 226 Try This: Toggling Between MapView’s Standard and Satellite Views . . 232 10 Using the Google API with GTalk . . 239 Configuring the Android Emulator for GTalk . . . 241 Implementing GTalk in Android . . . 244 Creating the Activity’s Layout in the GoogleAPI.xml . . . 245 Adding Packages to GoogleAPI.java . . . 247 Implementing the View.OnClickListener . . . 248 Compiling and Running GoogleAPI . . . 252 Try This: Add a Settings Feature to Your GoogleAPI Activity . . 255 11 Application: Find a Friend . . 257 Creating a SQLite Database . . . 259 Creating a Custom Content Provider . . 263 Editing the strings.xml . . 263 Creating Your Content Provider . . 265 Creating the FindAFriend Activity . . . 276 Editing AndroidManifest.xml . . 276 Creating the NameEditor Activity . . . 278 Creating the LocationEditor Activity . . . 283 Creating the FriendsMap Activity . . . 293 Creating the FindAFriend Activity . . 299 Running the FindAFriend Activity . . . 302 Try This: Real-Time Location Updating . . 305 12 Android SDK Tool Reference . . . 307 Android Emulator Commands . . . 308 Android Debug Bridge Commands . . . 310 Index . . 313
rar 文件大小:3.66MB