Wei-Meng Lee
Beginning Android 4 Application Development
2 Angebote ab € 9,99 €
Wei-Meng Lee
Beginning Android 4 Application Development
- Broschiertes Buch
- Merkliste
- Auf die Merkliste
- Bewerten Bewerten
- Teilen
- Produkt teilen
- Produkterinnerung
- Produkterinnerung
Understand Android OS for both smartphone and tablet programming
This fast-paced introduction to the newest release of Android OS gives aspiring mobile app developers what they need to know to program for today's hottest Android smartphones and tablets. Android 4 OS is, for the first time, a single solution for both smartphones and tablets, so if you master the information in this helpful guide, you'll be well on your way to successful development for both devices. From using activities and intents and creating rich user interfaces to working with SMS, messaging APIs, and the Android SDK,…mehr
Understand Android OS for both smartphone and tablet programming
This fast-paced introduction to the newest release of Android OS gives aspiring mobile app developers what they need to know to program for today's hottest Android smartphones and tablets. Android 4 OS is, for the first time, a single solution for both smartphones and tablets, so if you master the information in this helpful guide, you'll be well on your way to successful development for both devices. From using activities and intents and creating rich user interfaces to working with SMS, messaging APIs, and the Android SDK, what you need is here.
Provides clear instructions backed by real-world programming examples
Begins with the basics and covers everything Android 4 developers need to know for both smartphones and tablets
Explains how to customize activities and intents, create rich user interfaces, and manage data
Helps you work with SMS and messaging APIs, the Android SDK, and using location-based services
Details how to package and publish your applications to the Android Market
Beginning Android 4 Application Development pares down the most essential steps you need to know so you can start creating Android applications today.
This fast-paced introduction to the newest release of Android OS gives aspiring mobile app developers what they need to know to program for today's hottest Android smartphones and tablets. Android 4 OS is, for the first time, a single solution for both smartphones and tablets, so if you master the information in this helpful guide, you'll be well on your way to successful development for both devices. From using activities and intents and creating rich user interfaces to working with SMS, messaging APIs, and the Android SDK, what you need is here.
Provides clear instructions backed by real-world programming examples
Begins with the basics and covers everything Android 4 developers need to know for both smartphones and tablets
Explains how to customize activities and intents, create rich user interfaces, and manage data
Helps you work with SMS and messaging APIs, the Android SDK, and using location-based services
Details how to package and publish your applications to the Android Market
Beginning Android 4 Application Development pares down the most essential steps you need to know so you can start creating Android applications today.
Produktdetails
- Produktdetails
- Verlag: Wiley & Sons
- 1. Auflage
- Seitenzahl: 560
- Abmessung: 229mm x 188mm x 26mm
- Gewicht: 930g
- ISBN-13: 9781118199541
- ISBN-10: 1118199545
- Artikelnr.: 34161694
- Verlag: Wiley & Sons
- 1. Auflage
- Seitenzahl: 560
- Abmessung: 229mm x 188mm x 26mm
- Gewicht: 930g
- ISBN-13: 9781118199541
- ISBN-10: 1118199545
- Artikelnr.: 34161694
Wei-Meng Lee is a technologist and founder of Developer Learning Solutions, a technology company specializing in hands-on training in the latest Microsoft and Apple technologies. He is the author of Beginning Android Application Development and Beginning iOS 5 Application Development, as well as many other technology books and articles.
INTRODUCTION xxi
CHAPTER 1: GETTING STARTED WITH ANDROID PROGRAMMING 1
What Is Android? 2
Android Versions 2
Features of Android 3
Architecture of Android 4
Android Devices in the Market 6
The Android Market 8
The Android Developer Community 9
Obtaining the Required Tools 9
Android SDK 10
Installing the Android SDK Tools 11
Confi guring the Android SDK Manager 12
Eclipse 14
Android Development Tools (ADT) 15
Creating Android Virtual Devices (AVDs) 17
Creating Your First Android Application 20
Anatomy of an Android Application 29
Summary 33
CHAPTER 2: ACTIVITIES, FRAGMENTS, AND INTENTS 35
Understanding Activities 36
Applying Styles and Themes to an Activity 41
Hiding the Activity Title 41
Displaying a Dialog Window 42
Displaying a Progress Dialog 47
Displaying a More Sophisticated Progress Dialog 50
Linking Activities Using Intents 53
Resolving Intent Filter Collision 58
Returning Results from an Intent 59
Passing Data Using an Intent Object 63
Fragments 69
Adding Fragments Dynamically 73
Life Cycle of a Fragment 76
Interactions between Fragments 80
Calling Built-In Applications Using Intents 85
Understanding the Intent Object 89
Using Intent Filters 91
Adding Categories 96
Displaying Notifications 98
Summary 103
CHAPTER 3: GETTING TO KNOW THE ANDROID USER INTERFACE 105
Understanding the Components of a Screen 105
Views and ViewGroups 106
LinearLayout 107
AbsoluteLayout 115
TableLayout 116
RelativeLayout 117
FrameLayout 118
ScrollView 121
Adapting to Display Orientation 123
Anchoring Views 125
Resizing and Repositioning 127
Managing Changes to Screen Orientation 130
Persisting State Information during Changes in Confi guration 133
Detecting Orientation Changes 135
Controlling the Orientation of the Activity 135
Utilizing the Action Bar 136
Adding Action Items to the Action Bar 139
Customizing the Action Items and Application Icon 144
Creating the User Interface Programmatically 146
Listening for UI Notifications 148
Overriding Methods Defined in an Activity 149
Registering Events for Views 152
Summary 156
CHAPTER 4: DESIGNING YOUR USER INTERFACE WITH VIEWS 159
Using Basic Views 160
TextView View 160
Button, ImageButton, EditText, CheckBox, ToggleButton, RadioButton, and RadioGroup Views 161
ProgressBar View 171
AutoCompleteTextView View 177
Using Picker Views 179
TimePicker View 179
DatePicker View 184
Using List Views to Display Long Lists 191
ListView View 191
Using the Spinner View 199
Understanding Specialized Fragments 202
Using a ListFragment 202
Using a DialogFragment 207
Using a PreferenceFragment 210
Summary 214
CHAPTER 5: DISPLAYING PICTURES AND MENUS WITH VIEWS 219
Using Image Views to Display Pictures 219
Gallery and ImageView Views 220
ImageSwitcher 226
GridView 231
Using Menus with Views 234
Creating the Helper Methods 235
Options Menu 238
Context Menu 240
Some Additional Views 242
AnalogClock and DigitalClock Views 242
WebView 243
Summary 249
CHAPTER 6: DATA PERSISTENCE 251
Saving and Loading User Preferences 251
Accessing Preferences Using an Activity 252
Programmatically Retrieving and Modifying the Preferences Values 259
Changing the Default Name of the Preferences File 261
Persisting Data to Files 263
Saving to Internal Storage 263
Saving to External Storage (SD Card) 268
Choosing the Best Storage Option 271
Using Static Resources 272
Creating and Using Databases 273
Creating the DBAdapter Helper Class 273
Using the Database Programmatically 279
Pre-Creating the Database 285
Summary 289
CHAPTER 7: CONTENT PROVIDERS 293
Sharing Data in Android 293
Using a Content Provider 294
Predefi ned Query String Constants 300
Projections 303
Filtering 304
Sorting 305
Creating Your Own Content Providers 305
Using the Content Provider 314
Summary 319
CHAPTER 8: MESSAGING 321
SMS Messaging 321
Sending SMS Messages Programmatically 322
Getting Feedback after Sending a Message 325
Sending SMS Messages Using Intent 328
Receiving SMS Messages 329
Caveats and Warnings 344
Sending E-mail 345
Summary 347
CHAPTER 9: LOCATION-BASED SERVICES 351
Displaying Maps 352
Creating the Project 352
Obtaining the Maps API Key 353
Displaying the Map 355
Displaying the Zoom Control 358
Changing Views 361
Navigating to a Specific Location 363
Adding Markers 366
Getting the Location That Was Touched 369
Geocoding and Reverse Geocoding 371
Getting Location Data 375
Monitoring a Location 384
Project -- Building a Location Tracker 385
Summary 390
CHAPTER 10: NETWORKING 393
Consuming Web Services Using HTTP 393
Downloading Binary Data 396
Downloading Text Content 402
Accessing Web Services Using the GET Method 404
Consuming JSON Services 409
Sockets Programming 417
Summary 426
CHAPTER 11: DEVELOPING ANDROID SERVICES 429
Creating Your Own Services 429
Performing Long-Running Tasks in a Service 433
Performing Repeated Tasks in a Service 439
Executing Asynchronous Tasks on Separate Threads Using IntentService 442
Establishing Communication between a Service and an Activity 445
Binding Activities to Services 449
Understanding Threading 454
Summary 460
CHAPTER 12: PUBLISHING ANDROID APPLICATIONS 463
Preparing for Publishing 463
Versioning Your Application 464
Digitally Signing Your Android Applications 466
Deploying APK Files 471
Using the adb.exe Tool 471
Using a Web Server 474
Publishing on the Android Market 476
Summary 481
APPENDIX A: USING ECLIPSE FOR ANDROID DEVELOPMENT 483
Getting Around in Eclipse 483
Workspaces 483
Package Explorer 485
Using Projects from Other Workspaces 486
Using Editors within Eclipse 487
Understanding Eclipse Perspectives 490
Automatically Importing Packages 490
Using the Code Completion Feature 491
Refactoring 492
Debugging your Application 494
Setting Breakpoints 495
Dealing with Exceptions 497
APPENDIX B: USING THE ANDROID EMULATOR 499
Uses of the Android Emulator 499
Creating Snapshots 501
SD Card Emulation 502
Emulating Devices with Different Screen Sizes 504
Emulating Physical Capabilities 506
Sending SMS Messages to the Emulator 508
Making Phone Calls 509
Transferring Files into and out of the Emulator 511
Resetting the Emulator 513
APPENDIX C: ANSWERS TO EXERCISES 515
INDEX 521
CHAPTER 1: GETTING STARTED WITH ANDROID PROGRAMMING 1
What Is Android? 2
Android Versions 2
Features of Android 3
Architecture of Android 4
Android Devices in the Market 6
The Android Market 8
The Android Developer Community 9
Obtaining the Required Tools 9
Android SDK 10
Installing the Android SDK Tools 11
Confi guring the Android SDK Manager 12
Eclipse 14
Android Development Tools (ADT) 15
Creating Android Virtual Devices (AVDs) 17
Creating Your First Android Application 20
Anatomy of an Android Application 29
Summary 33
CHAPTER 2: ACTIVITIES, FRAGMENTS, AND INTENTS 35
Understanding Activities 36
Applying Styles and Themes to an Activity 41
Hiding the Activity Title 41
Displaying a Dialog Window 42
Displaying a Progress Dialog 47
Displaying a More Sophisticated Progress Dialog 50
Linking Activities Using Intents 53
Resolving Intent Filter Collision 58
Returning Results from an Intent 59
Passing Data Using an Intent Object 63
Fragments 69
Adding Fragments Dynamically 73
Life Cycle of a Fragment 76
Interactions between Fragments 80
Calling Built-In Applications Using Intents 85
Understanding the Intent Object 89
Using Intent Filters 91
Adding Categories 96
Displaying Notifications 98
Summary 103
CHAPTER 3: GETTING TO KNOW THE ANDROID USER INTERFACE 105
Understanding the Components of a Screen 105
Views and ViewGroups 106
LinearLayout 107
AbsoluteLayout 115
TableLayout 116
RelativeLayout 117
FrameLayout 118
ScrollView 121
Adapting to Display Orientation 123
Anchoring Views 125
Resizing and Repositioning 127
Managing Changes to Screen Orientation 130
Persisting State Information during Changes in Confi guration 133
Detecting Orientation Changes 135
Controlling the Orientation of the Activity 135
Utilizing the Action Bar 136
Adding Action Items to the Action Bar 139
Customizing the Action Items and Application Icon 144
Creating the User Interface Programmatically 146
Listening for UI Notifications 148
Overriding Methods Defined in an Activity 149
Registering Events for Views 152
Summary 156
CHAPTER 4: DESIGNING YOUR USER INTERFACE WITH VIEWS 159
Using Basic Views 160
TextView View 160
Button, ImageButton, EditText, CheckBox, ToggleButton, RadioButton, and RadioGroup Views 161
ProgressBar View 171
AutoCompleteTextView View 177
Using Picker Views 179
TimePicker View 179
DatePicker View 184
Using List Views to Display Long Lists 191
ListView View 191
Using the Spinner View 199
Understanding Specialized Fragments 202
Using a ListFragment 202
Using a DialogFragment 207
Using a PreferenceFragment 210
Summary 214
CHAPTER 5: DISPLAYING PICTURES AND MENUS WITH VIEWS 219
Using Image Views to Display Pictures 219
Gallery and ImageView Views 220
ImageSwitcher 226
GridView 231
Using Menus with Views 234
Creating the Helper Methods 235
Options Menu 238
Context Menu 240
Some Additional Views 242
AnalogClock and DigitalClock Views 242
WebView 243
Summary 249
CHAPTER 6: DATA PERSISTENCE 251
Saving and Loading User Preferences 251
Accessing Preferences Using an Activity 252
Programmatically Retrieving and Modifying the Preferences Values 259
Changing the Default Name of the Preferences File 261
Persisting Data to Files 263
Saving to Internal Storage 263
Saving to External Storage (SD Card) 268
Choosing the Best Storage Option 271
Using Static Resources 272
Creating and Using Databases 273
Creating the DBAdapter Helper Class 273
Using the Database Programmatically 279
Pre-Creating the Database 285
Summary 289
CHAPTER 7: CONTENT PROVIDERS 293
Sharing Data in Android 293
Using a Content Provider 294
Predefi ned Query String Constants 300
Projections 303
Filtering 304
Sorting 305
Creating Your Own Content Providers 305
Using the Content Provider 314
Summary 319
CHAPTER 8: MESSAGING 321
SMS Messaging 321
Sending SMS Messages Programmatically 322
Getting Feedback after Sending a Message 325
Sending SMS Messages Using Intent 328
Receiving SMS Messages 329
Caveats and Warnings 344
Sending E-mail 345
Summary 347
CHAPTER 9: LOCATION-BASED SERVICES 351
Displaying Maps 352
Creating the Project 352
Obtaining the Maps API Key 353
Displaying the Map 355
Displaying the Zoom Control 358
Changing Views 361
Navigating to a Specific Location 363
Adding Markers 366
Getting the Location That Was Touched 369
Geocoding and Reverse Geocoding 371
Getting Location Data 375
Monitoring a Location 384
Project -- Building a Location Tracker 385
Summary 390
CHAPTER 10: NETWORKING 393
Consuming Web Services Using HTTP 393
Downloading Binary Data 396
Downloading Text Content 402
Accessing Web Services Using the GET Method 404
Consuming JSON Services 409
Sockets Programming 417
Summary 426
CHAPTER 11: DEVELOPING ANDROID SERVICES 429
Creating Your Own Services 429
Performing Long-Running Tasks in a Service 433
Performing Repeated Tasks in a Service 439
Executing Asynchronous Tasks on Separate Threads Using IntentService 442
Establishing Communication between a Service and an Activity 445
Binding Activities to Services 449
Understanding Threading 454
Summary 460
CHAPTER 12: PUBLISHING ANDROID APPLICATIONS 463
Preparing for Publishing 463
Versioning Your Application 464
Digitally Signing Your Android Applications 466
Deploying APK Files 471
Using the adb.exe Tool 471
Using a Web Server 474
Publishing on the Android Market 476
Summary 481
APPENDIX A: USING ECLIPSE FOR ANDROID DEVELOPMENT 483
Getting Around in Eclipse 483
Workspaces 483
Package Explorer 485
Using Projects from Other Workspaces 486
Using Editors within Eclipse 487
Understanding Eclipse Perspectives 490
Automatically Importing Packages 490
Using the Code Completion Feature 491
Refactoring 492
Debugging your Application 494
Setting Breakpoints 495
Dealing with Exceptions 497
APPENDIX B: USING THE ANDROID EMULATOR 499
Uses of the Android Emulator 499
Creating Snapshots 501
SD Card Emulation 502
Emulating Devices with Different Screen Sizes 504
Emulating Physical Capabilities 506
Sending SMS Messages to the Emulator 508
Making Phone Calls 509
Transferring Files into and out of the Emulator 511
Resetting the Emulator 513
APPENDIX C: ANSWERS TO EXERCISES 515
INDEX 521
INTRODUCTION xxi
CHAPTER 1: GETTING STARTED WITH ANDROID PROGRAMMING 1
What Is Android? 2
Android Versions 2
Features of Android 3
Architecture of Android 4
Android Devices in the Market 6
The Android Market 8
The Android Developer Community 9
Obtaining the Required Tools 9
Android SDK 10
Installing the Android SDK Tools 11
Confi guring the Android SDK Manager 12
Eclipse 14
Android Development Tools (ADT) 15
Creating Android Virtual Devices (AVDs) 17
Creating Your First Android Application 20
Anatomy of an Android Application 29
Summary 33
CHAPTER 2: ACTIVITIES, FRAGMENTS, AND INTENTS 35
Understanding Activities 36
Applying Styles and Themes to an Activity 41
Hiding the Activity Title 41
Displaying a Dialog Window 42
Displaying a Progress Dialog 47
Displaying a More Sophisticated Progress Dialog 50
Linking Activities Using Intents 53
Resolving Intent Filter Collision 58
Returning Results from an Intent 59
Passing Data Using an Intent Object 63
Fragments 69
Adding Fragments Dynamically 73
Life Cycle of a Fragment 76
Interactions between Fragments 80
Calling Built-In Applications Using Intents 85
Understanding the Intent Object 89
Using Intent Filters 91
Adding Categories 96
Displaying Notifications 98
Summary 103
CHAPTER 3: GETTING TO KNOW THE ANDROID USER INTERFACE 105
Understanding the Components of a Screen 105
Views and ViewGroups 106
LinearLayout 107
AbsoluteLayout 115
TableLayout 116
RelativeLayout 117
FrameLayout 118
ScrollView 121
Adapting to Display Orientation 123
Anchoring Views 125
Resizing and Repositioning 127
Managing Changes to Screen Orientation 130
Persisting State Information during Changes in Confi guration 133
Detecting Orientation Changes 135
Controlling the Orientation of the Activity 135
Utilizing the Action Bar 136
Adding Action Items to the Action Bar 139
Customizing the Action Items and Application Icon 144
Creating the User Interface Programmatically 146
Listening for UI Notifications 148
Overriding Methods Defined in an Activity 149
Registering Events for Views 152
Summary 156
CHAPTER 4: DESIGNING YOUR USER INTERFACE WITH VIEWS 159
Using Basic Views 160
TextView View 160
Button, ImageButton, EditText, CheckBox, ToggleButton, RadioButton, and RadioGroup Views 161
ProgressBar View 171
AutoCompleteTextView View 177
Using Picker Views 179
TimePicker View 179
DatePicker View 184
Using List Views to Display Long Lists 191
ListView View 191
Using the Spinner View 199
Understanding Specialized Fragments 202
Using a ListFragment 202
Using a DialogFragment 207
Using a PreferenceFragment 210
Summary 214
CHAPTER 5: DISPLAYING PICTURES AND MENUS WITH VIEWS 219
Using Image Views to Display Pictures 219
Gallery and ImageView Views 220
ImageSwitcher 226
GridView 231
Using Menus with Views 234
Creating the Helper Methods 235
Options Menu 238
Context Menu 240
Some Additional Views 242
AnalogClock and DigitalClock Views 242
WebView 243
Summary 249
CHAPTER 6: DATA PERSISTENCE 251
Saving and Loading User Preferences 251
Accessing Preferences Using an Activity 252
Programmatically Retrieving and Modifying the Preferences Values 259
Changing the Default Name of the Preferences File 261
Persisting Data to Files 263
Saving to Internal Storage 263
Saving to External Storage (SD Card) 268
Choosing the Best Storage Option 271
Using Static Resources 272
Creating and Using Databases 273
Creating the DBAdapter Helper Class 273
Using the Database Programmatically 279
Pre-Creating the Database 285
Summary 289
CHAPTER 7: CONTENT PROVIDERS 293
Sharing Data in Android 293
Using a Content Provider 294
Predefi ned Query String Constants 300
Projections 303
Filtering 304
Sorting 305
Creating Your Own Content Providers 305
Using the Content Provider 314
Summary 319
CHAPTER 8: MESSAGING 321
SMS Messaging 321
Sending SMS Messages Programmatically 322
Getting Feedback after Sending a Message 325
Sending SMS Messages Using Intent 328
Receiving SMS Messages 329
Caveats and Warnings 344
Sending E-mail 345
Summary 347
CHAPTER 9: LOCATION-BASED SERVICES 351
Displaying Maps 352
Creating the Project 352
Obtaining the Maps API Key 353
Displaying the Map 355
Displaying the Zoom Control 358
Changing Views 361
Navigating to a Specific Location 363
Adding Markers 366
Getting the Location That Was Touched 369
Geocoding and Reverse Geocoding 371
Getting Location Data 375
Monitoring a Location 384
Project -- Building a Location Tracker 385
Summary 390
CHAPTER 10: NETWORKING 393
Consuming Web Services Using HTTP 393
Downloading Binary Data 396
Downloading Text Content 402
Accessing Web Services Using the GET Method 404
Consuming JSON Services 409
Sockets Programming 417
Summary 426
CHAPTER 11: DEVELOPING ANDROID SERVICES 429
Creating Your Own Services 429
Performing Long-Running Tasks in a Service 433
Performing Repeated Tasks in a Service 439
Executing Asynchronous Tasks on Separate Threads Using IntentService 442
Establishing Communication between a Service and an Activity 445
Binding Activities to Services 449
Understanding Threading 454
Summary 460
CHAPTER 12: PUBLISHING ANDROID APPLICATIONS 463
Preparing for Publishing 463
Versioning Your Application 464
Digitally Signing Your Android Applications 466
Deploying APK Files 471
Using the adb.exe Tool 471
Using a Web Server 474
Publishing on the Android Market 476
Summary 481
APPENDIX A: USING ECLIPSE FOR ANDROID DEVELOPMENT 483
Getting Around in Eclipse 483
Workspaces 483
Package Explorer 485
Using Projects from Other Workspaces 486
Using Editors within Eclipse 487
Understanding Eclipse Perspectives 490
Automatically Importing Packages 490
Using the Code Completion Feature 491
Refactoring 492
Debugging your Application 494
Setting Breakpoints 495
Dealing with Exceptions 497
APPENDIX B: USING THE ANDROID EMULATOR 499
Uses of the Android Emulator 499
Creating Snapshots 501
SD Card Emulation 502
Emulating Devices with Different Screen Sizes 504
Emulating Physical Capabilities 506
Sending SMS Messages to the Emulator 508
Making Phone Calls 509
Transferring Files into and out of the Emulator 511
Resetting the Emulator 513
APPENDIX C: ANSWERS TO EXERCISES 515
INDEX 521
CHAPTER 1: GETTING STARTED WITH ANDROID PROGRAMMING 1
What Is Android? 2
Android Versions 2
Features of Android 3
Architecture of Android 4
Android Devices in the Market 6
The Android Market 8
The Android Developer Community 9
Obtaining the Required Tools 9
Android SDK 10
Installing the Android SDK Tools 11
Confi guring the Android SDK Manager 12
Eclipse 14
Android Development Tools (ADT) 15
Creating Android Virtual Devices (AVDs) 17
Creating Your First Android Application 20
Anatomy of an Android Application 29
Summary 33
CHAPTER 2: ACTIVITIES, FRAGMENTS, AND INTENTS 35
Understanding Activities 36
Applying Styles and Themes to an Activity 41
Hiding the Activity Title 41
Displaying a Dialog Window 42
Displaying a Progress Dialog 47
Displaying a More Sophisticated Progress Dialog 50
Linking Activities Using Intents 53
Resolving Intent Filter Collision 58
Returning Results from an Intent 59
Passing Data Using an Intent Object 63
Fragments 69
Adding Fragments Dynamically 73
Life Cycle of a Fragment 76
Interactions between Fragments 80
Calling Built-In Applications Using Intents 85
Understanding the Intent Object 89
Using Intent Filters 91
Adding Categories 96
Displaying Notifications 98
Summary 103
CHAPTER 3: GETTING TO KNOW THE ANDROID USER INTERFACE 105
Understanding the Components of a Screen 105
Views and ViewGroups 106
LinearLayout 107
AbsoluteLayout 115
TableLayout 116
RelativeLayout 117
FrameLayout 118
ScrollView 121
Adapting to Display Orientation 123
Anchoring Views 125
Resizing and Repositioning 127
Managing Changes to Screen Orientation 130
Persisting State Information during Changes in Confi guration 133
Detecting Orientation Changes 135
Controlling the Orientation of the Activity 135
Utilizing the Action Bar 136
Adding Action Items to the Action Bar 139
Customizing the Action Items and Application Icon 144
Creating the User Interface Programmatically 146
Listening for UI Notifications 148
Overriding Methods Defined in an Activity 149
Registering Events for Views 152
Summary 156
CHAPTER 4: DESIGNING YOUR USER INTERFACE WITH VIEWS 159
Using Basic Views 160
TextView View 160
Button, ImageButton, EditText, CheckBox, ToggleButton, RadioButton, and RadioGroup Views 161
ProgressBar View 171
AutoCompleteTextView View 177
Using Picker Views 179
TimePicker View 179
DatePicker View 184
Using List Views to Display Long Lists 191
ListView View 191
Using the Spinner View 199
Understanding Specialized Fragments 202
Using a ListFragment 202
Using a DialogFragment 207
Using a PreferenceFragment 210
Summary 214
CHAPTER 5: DISPLAYING PICTURES AND MENUS WITH VIEWS 219
Using Image Views to Display Pictures 219
Gallery and ImageView Views 220
ImageSwitcher 226
GridView 231
Using Menus with Views 234
Creating the Helper Methods 235
Options Menu 238
Context Menu 240
Some Additional Views 242
AnalogClock and DigitalClock Views 242
WebView 243
Summary 249
CHAPTER 6: DATA PERSISTENCE 251
Saving and Loading User Preferences 251
Accessing Preferences Using an Activity 252
Programmatically Retrieving and Modifying the Preferences Values 259
Changing the Default Name of the Preferences File 261
Persisting Data to Files 263
Saving to Internal Storage 263
Saving to External Storage (SD Card) 268
Choosing the Best Storage Option 271
Using Static Resources 272
Creating and Using Databases 273
Creating the DBAdapter Helper Class 273
Using the Database Programmatically 279
Pre-Creating the Database 285
Summary 289
CHAPTER 7: CONTENT PROVIDERS 293
Sharing Data in Android 293
Using a Content Provider 294
Predefi ned Query String Constants 300
Projections 303
Filtering 304
Sorting 305
Creating Your Own Content Providers 305
Using the Content Provider 314
Summary 319
CHAPTER 8: MESSAGING 321
SMS Messaging 321
Sending SMS Messages Programmatically 322
Getting Feedback after Sending a Message 325
Sending SMS Messages Using Intent 328
Receiving SMS Messages 329
Caveats and Warnings 344
Sending E-mail 345
Summary 347
CHAPTER 9: LOCATION-BASED SERVICES 351
Displaying Maps 352
Creating the Project 352
Obtaining the Maps API Key 353
Displaying the Map 355
Displaying the Zoom Control 358
Changing Views 361
Navigating to a Specific Location 363
Adding Markers 366
Getting the Location That Was Touched 369
Geocoding and Reverse Geocoding 371
Getting Location Data 375
Monitoring a Location 384
Project -- Building a Location Tracker 385
Summary 390
CHAPTER 10: NETWORKING 393
Consuming Web Services Using HTTP 393
Downloading Binary Data 396
Downloading Text Content 402
Accessing Web Services Using the GET Method 404
Consuming JSON Services 409
Sockets Programming 417
Summary 426
CHAPTER 11: DEVELOPING ANDROID SERVICES 429
Creating Your Own Services 429
Performing Long-Running Tasks in a Service 433
Performing Repeated Tasks in a Service 439
Executing Asynchronous Tasks on Separate Threads Using IntentService 442
Establishing Communication between a Service and an Activity 445
Binding Activities to Services 449
Understanding Threading 454
Summary 460
CHAPTER 12: PUBLISHING ANDROID APPLICATIONS 463
Preparing for Publishing 463
Versioning Your Application 464
Digitally Signing Your Android Applications 466
Deploying APK Files 471
Using the adb.exe Tool 471
Using a Web Server 474
Publishing on the Android Market 476
Summary 481
APPENDIX A: USING ECLIPSE FOR ANDROID DEVELOPMENT 483
Getting Around in Eclipse 483
Workspaces 483
Package Explorer 485
Using Projects from Other Workspaces 486
Using Editors within Eclipse 487
Understanding Eclipse Perspectives 490
Automatically Importing Packages 490
Using the Code Completion Feature 491
Refactoring 492
Debugging your Application 494
Setting Breakpoints 495
Dealing with Exceptions 497
APPENDIX B: USING THE ANDROID EMULATOR 499
Uses of the Android Emulator 499
Creating Snapshots 501
SD Card Emulation 502
Emulating Devices with Different Screen Sizes 504
Emulating Physical Capabilities 506
Sending SMS Messages to the Emulator 508
Making Phone Calls 509
Transferring Files into and out of the Emulator 511
Resetting the Emulator 513
APPENDIX C: ANSWERS TO EXERCISES 515
INDEX 521