Wiley
Wiley.com
Print this page Share

Professional Android 2 Application Development

ISBN: 978-0-470-56552-0
576 pages
March 2010
Professional Android 2 Application Development (0470565527) cover image

Description

Update to the bestseller now features the latest release of the Android platform

Android is a powerful, flexible, open source platform for mobile devices and its popularity is growing at an unprecedented pace. This update to the bestselling first edition dives in to cover the exciting new features of the latest release of the Android mobile platform.

Providing in-depth coverage of how to build mobile applications using the next major release of the Android SDK, this invaluable resource takes a hands-on approach to discussing Android with a series of projects, each of which introduces a new feature and highlights techniques and best practices to get the most out of Android.

  • The Android SDK is a powerful, flexible, open source platform for mobile devices
  • Shares helpful techniques and best practices to maximize the capabilities of Android
  • Explains the possibilities of Android through the use of a series of detailed projects
  • Demonstrates how to create real-world mobile applications for Android phones
  • Includes coverage of the latest version of Android

Providing concise and compelling examples, Professional Android Application Development is an updated guide aimed at helping you create mobile applications for mobile devices running the latest version of Android.

See More

Table of Contents

INTRODUCTION xxvii

CHAPTER 1: HELLO, ANDROID 1

A Little Background 2

What It Isn’t 3

Android: An Open Platform for Mobile Development 4

Native Android Applications 5

Android SDK Features 6

Introducing the Open Handset Alliance 9

What Does Android Run On? 9

Why Develop for Mobile? 9

Why Develop for Android? 10

Introducing the Development Framework 12

Summary 16

CHAPTER 2: GETTING STARTED 17

Developing for Android 18

Developing for Mobile Devices 30

To-Do List Example 38

Android Development Tools 43

Summary 48

CHAPTER 3: CREATING APPLICATIONS AND ACTIVITIES 49

What Makes an Android Application? 50

Introducing the Application Manifest 51

Using the Manifest Editor 56

The Android Application Life Cycle 57

Understanding Application Priority and Process States 58

Externalizing Resources 59

Introducing the Android Application Class 74

A Closer Look at Android Activities 76

Summary 84

CHAPTER 4: CREATING USER INTERFACES 85

Fundamental Android UI Design 86

Introducing Views 86

Introducing Layouts 89

Creating New Views 91

Drawable Resources 111

Resolution and Density Independence 117

Creating and Using Menus 123

Summary 136

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

Introducing Intents 138

Introducing Pending Intents 162

Introducing Adapters 163

Using Internet Resources 170

Introducing Dialogs 172

Creating an Earthquake Viewer 176

Summary 184

CHAPTER 6: FILES, SAVING STATE, AND PREFERENCES 187

Saving Simple Application Data 188

Creating and Saving Preferences 188

Retrieving Shared Preferences 189

Creating a Settings Activity for the Earthquake Viewer 189

Introducing the Preference Activity and Preferences Framework 197

Creating a Standard Preference Activity for the Earthquake Viewer 202

Saving Activity State 203

Saving and Loading Files 207

Including Static Files as Resources 207

File Management Tools 208

Summary 208

CHAPTER 7: DATABASES AND CONTENT PROVIDERS 209

Introducing Android Databases 209

Introducing SQLite 210

Cursors and Content Values 211

Working with SQLite Databases 211

Creating a New Content Provider 224

Using Content Providers 227

Creating and Using an Earthquake Content Provider 230

Native Android Content Providers 238

Summary 244

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

Using Location-Based Services 246

Configuring the Emulator to Test Location-Based Services 246

Updating Locations in Emulator Location Providers 246

Selecting a Location Provider 247

Finding Your Location 249

Using Proximity Alerts 255

Using the Geocoder 256

Creating Map-Based Activities 260

Mapping Earthquakes Example 279

Summary 284

CHAPTER 9: WORKING IN THE BACKGROUND 285

Introducing Services 286

Using Background Threads 300

Let’s Make a Toast 306

Introducing Notifications 309

Using Alarms 320

Summary 325

CHAPTER 10: INVADING THE PHONE-TOP 327

Introducing Home-Screen Widgets 328

Creating App Widgets 328

Creating an Earthquake Widget 341

Introducing Live Folders 346

Adding Search to Your Applications and the Quick Search Box 351

Creating Live Wallpaper 358

Summary 361

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

Playing Audio and Video 364

Recording Audio and Video 371

Using the Camera and Taking Pictures 375

Adding New Media to the Media Store 382

Raw Audio Manipulation 384

Speech Recognition 386

Summary 388

CHAPTER 12: TELEPHONY AND SMS 389

Telephony 390

Introducing SMS and MMS 398

Summary 423

CHAPTER 13: BLUETOOTH, NETWORKS, AND WI-FI 425

Using Bluetooth 425

Managing Network Connectivity 448

Managing Your Wi-Fi 452

Summary 455

CHAPTER 14: SENSORS 457

Using Sensors and the Sensor Manager 458

Interpreting Sensor Values 461

Using the Compass, Accelerometer, and Orientation Sensors 462

Controlling Device Vibration 474

Summary 475

CHAPTER 15: ADVANCED ANDROID DEVELOPMENT 477

Paranoid Android 478

Using Wake Locks 480

Introducing Android Text to Speech 481

Using AIDL to Support IPC for Services 483

Using Internet Services 488

Building Rich User Interfaces 489

Summary 526

INDEX 529

See More

Author Information

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.
See More

Downloads

Download TitleSizeDownload
Code Download :: Code Listings 47.13 KB Click to Download
Code Download :: Example Projects 738.86 KB Click to Download
See More

Errata

Do you think you've discovered an error in this book? Please check the list of errata below to see if we've already addressed the error. If not, please submit the error via our Errata Form. We will attempt to verify your error; if you're right, we will post a correction below.

ChapterPageDetailsDatePrint Run
26 Error in Text
On page 26, in the tip box at line 4:

The text refers to the "Manage..." button, but the name of the button is actually "Manager..."
12/28/2010
53 Error in Text
On top of page, first paragraph:
QUERTY should be QWERTY
11/29/2010
80 Error in Text
In Figure 3.7 the state block "onSaveInstanceState" and "onRestoreInstanceState" should be swapped.
3/9/10
108 Error in Code
Section 5: in the code listing for the initCompassView method, the variable 'r' is referenced before it is declared, in the line 'circlePaint.setColor(r.getColor(R.color.background_color));'.

should read:
Resources r = this.getResources(); 

circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG); 
circlePaint.setColor(r.getColor(R.color.background_color)); 
circlePaint.setStrokeWidth(1); 
circlePaint.setStyle(Paint.Style.FILL_AND_STROKE); 

northString = r.getString(R.String.cardinal_north);
12/31/2010
111-117 Error in Text
Ch.4, Drawable resources:
The paragraph shows various "snippets" of code/xml (the listings), but forgets to mention how to actually "use" a drawable resource, e.g. referring to it in some xml layout or in some activity code.
12/13/2010
127 Error in Text
Ch.10, 'Dynamically Updating Menu Items', 2nd paragraph, 1st sentence:

in sentence:
'[...] you can either find a reference to them in the onCreateOptionsMenu [...]'
'find' should be substituted in favor of 'store' or something similar.
12/13/2010
129-130 Error in Code
Ch.4, Listing 4-29:

All 3 occurences of 'menu.FIRST' should be 'Menu.FIRST', so not to issue compiler warnings as FIRST is static.

The code invokes 'setIcon' method on a menu item from a context menu. But as said in following explanation, icons on those items are not displayed, while icons are displayed for context menu header. Should invoke 'setHeaderIcon' on context menu.
12/13/2010
131 Error in Text
Ch-4, last sentence before listing 4-31:

typo: 'MenuInflator' --> 'MenuInflater'
12/13/2010
4 133 Error in Text
step. 6:Although the text says "For the code in Step 5 to work you need to increase the scope of the todoListItems and ListView control beyond the onCreate method", only ListView scope needs to increase. In step 5 todoListItems is not used at all.
12/13/2010
5 141 Error in Text
Listing 5-5:

catpion should read ?Returning results from an Activity?.
01/02/2011
146 Error in Text
In Listing 5-7, line 5:

android.intent.category.ALTERNATIVE_SELECTED

Should be

android.intent.category.SELECTED_ALTERNATIVE

3/10/10
7 232 Error in Code
The text to initialize DATABASE_CREATE constant in earthquakeDatabaseHelper class has an aditional parenthesis, which provokes an SQLLiteException syntax error:
+ KEY_MAGNITUDE + " FLOAT), "

Should read:
+ KEY_MAGNITUDE + " FLOAT, "
4/14/2011
8 276 Error in Code
Listing 8-12:
case 1

should be:
case 0
4/14/2011
8 281 Error in Code
Step 5.1:

"ContentResolver resolver" is not needed in this piece of code. Should be (all on one line):

public EarthquakeOverlay(Cursor cursor) {
4/14/2011
8 283 Error in Code
Step 6:
String earthquakeURI = ...

Should be

Uri earthquakeURI = EarthquakeProvider.CONTENT_URI; 
01/02/2011
9 290 Error in Note
Replace both instances of MY_ACTION in the note to ORDER_PIZZA
4/14/2011
9 294 Error in Code
Step 5:

Preferences.USER_PREFERENCE was not defined in pre-existing code
01/02/2011
9 296 Error in Code
Step 7.1:

loadFromProviders

Should be:
loadQuakesFromProvider
loadQuakesFromProvider
01/02/2011
9 297 Error in Code
Step 7.3:

earthquakeCursor.deactivate()
should not be bold

AND insert the following additional line immediately before the above mentioned line. The inserted line should be bold:
unregisterReceiver(receiver)
4/14/2011
13 450 Error in Code
listing 13-13:
},
should be: }},
4/14/11
450 Error in Code
Ch.13 p.450 listing 13-14:
int networkType = networkInfo.getType();

should be:
int networkType = activeNetwork.getType();

Replace "networkInfo" with "activeNetwork"
4/14/11
13 451 Error in Code
'Finding and Configuring Network Preferences and Controlling Hardware Radios':

Prefix the sentence that starts, "You can find the current..." with "In some versions of Android, "
4/14/11
See More

Related Titles

Back to Top