Android Cookbook |
Jump in and build working Android apps with the help of more than 200 tested recipes. With this cookbook, you’ll find solutions for working with the user interfaces, multitouch gestures, location awareness, web services, and device features such as the phone, camera, and accelerometer. You also get useful steps on packaging your app for the Android Market.
Ideal for developers familiar with Java, Android basics, and the Java SE API, this book features recipes contributed by more than three dozen developers from the Android community. Each recipe provides a clear solution and sample code you can use in your project right away. Among numerous topics, this cookbook helps you:
Ian F. Darwin has worked in the computer industry for three decades. He wrote the freeware file(1) command used on Linux and BSD and is the author of Checking C Programs with Lint, Java Cookbook, and over seventy articles and courses on C and Unix. In addition to programming and consulting, Ian teaches Unix, C, and Java for Learning Tree International, one of the world's largest technical training companies.
Table of Contents
Ideal for developers familiar with Java, Android basics, and the Java SE API, this book features recipes contributed by more than three dozen developers from the Android community. Each recipe provides a clear solution and sample code you can use in your project right away. Among numerous topics, this cookbook helps you:
- Use guidelines for designing a successful Android app
- Work with UI controls, effective layouts, and graphical elements
- Learn how to take advantage of Android’s rich features in your app
- Save and retrieve application data in files, SD cards, and embedded databases
- Access RESTful web services, RSS/Atom feeds, and information from websites
- Create location-aware services to find locations and landmarks, and situate them on Google Maps and OpenStreetMap
- Test and troubleshoot individual components and your entire application
Ian F. Darwin has worked in the computer industry for three decades. He wrote the freeware file(1) command used on Linux and BSD and is the author of Checking C Programs with Lint, Java Cookbook, and over seventy articles and courses on C and Unix. In addition to programming and consulting, Ian teaches Unix, C, and Java for Learning Tree International, one of the world's largest technical training companies.
Chapter 1 Getting Started
- Introduction: Getting Started
- Learning the Java Language
- Creating a “Hello, World” Application from the Command Line
- Creating a “Hello, World” Application in Eclipse
- Setting Up an IDE on Windows to Develop for Android
- Understanding the Android Life Cycle
- Installing .apk Files onto an Emulator via the ADB
- Installing Apps onto an Emulator via SlideME
- Sharing Java Classes from Another Eclipse Project
- Referencing Libraries to Implement External Functionality
- Using SDK Samples to Help Avoid Head Scratching
- Keeping the Android SDK Updated
- Taking a Screenshot from the Emulator/Android Device
- Program: A Simple CountDownTimer Example
- Program: Tipster, a Tip Calculator for the Android OS
- Introduction: Designing a Successful Android Application
- Exception Handling
- Accessing Android’s Application Object as a “Singleton”
- Keeping Data When the User Rotates the Device
- Monitoring the Battery Level of an Android Device
- Creating Splash Screens in Android
- Designing a Conference/Camp/Hackathon/Institution App
- Using Google Analytics in an Android Application
- A Simple Torch/Flashlight
- Adapting an Android Phone Application to Be Used on a Tablet
- Setting First-Run Preferences
- Formatting the Time and Date for Display
- Controlling Input with KeyListeners
- Backing Up Android Application Data
- Using Hints Instead of Tool Tips
- Introduction: Testing
- Doing Test-Driven Development (TDD) in Android
- Setting Up an Android Virtual Device (AVD) for App Testing
- Testing on a Huge Range of Devices with Cloud-based Testing
- Creating and Using a Test Project
- Troubleshooting Application Crashes
- Debugging Using Log.d and LogCat
- Getting Bug Reports from Users Automatically with BugSense
- Using a Local Runtime Application Log for Analysis of Field Errors or Situations
- Reproducing Activity Life-Cycle Scenarios for Testing
- Keeping Your App Snappy with StrictMode
- Running the Monkey Program
- Sending Text Messages and Placing Calls Between AVDs
- Introduction: Inter-/Intra-Process Communication
- Opening a Web Page, Phone Number, or Anything Else with an Intent
- Emailing Text from a View
- Sending an Email with Attachments
- Pushing String Values Using Intent.putExtra()
- Retrieving Data from a Subactivity Back to Your Main Activity
- Keeping a Service Running While Other Apps Are on Display
- Sending/Receiving a Broadcast Message
- Starting a Service After Device Reboot
- Creating a Responsive Application Using Threads
- Using AsyncTask to Do Background Processing
- Sending Messages Between Threads Using an Activity Thread Queue and Handler
- Creating an Android Epoch HTML/JavaScript Calendar
- Introduction: Content Providers
- Retrieving Data from a Content Provider
- Writing a Content Provider
- Writing an Android Remote Service
- Introduction: Graphics
- Using a Custom Font
- Drawing a Spinning Cube with OpenGL ES
- Adding Controls to the OpenGL Spinning Cube
- Freehand Drawing Smooth Curves
- Taking a Picture Using an Intent
- Taking a Picture Using android.media.Camera
- Scanning a Barcode or QR Code with the Google ZXing Barcode Scanner
- Using AndroidPlot to Display Charts and Graphs
- Using Inkscape to Create an Android Launcher Icon
- Creating Easy Launcher Icons from OpenClipArt.org Using Paint.NET
- Using Nine Patch Files
- Creating HTML5 Charts with Android RGraph
- Adding a Simple Raster Animation
- Using Pinch to Zoom
- Introduction: GUI
- Understanding and Following User Interface Guidelines
- Handling Configuration Changes by Decoupling the View from the Model
- Creating a Button and Its Click Event Listener
- Wiring Up an Event Listener in Five Different Ways
- Using CheckBoxes and RadioButtons
- Enhancing UI Design Using Image Buttons
- Offering a Drop-Down Chooser via the Spinner Class
- Handling Long-Press/Long-Click Events
- Displaying Text Fields with TextView and EditText
- Constraining EditText Values with Attributes and the TextWatcher Interface
- Implementing AutoCompleteTextView
- Feeding AutoCompleteTextView Using an SQLite Database Query
- Turning Edit Fields into Password Fields
- Changing the Enter Key to “Next” on the Soft Keyboard
- Processing Key-Press Events in an Activity
- Let Them See Stars: Using RatingBar
- Making a View Shake
- Providing Haptic Feedback
- Navigating Different Activities Within a TabView
- Creating a Custom Title Bar
- Formatting Numbers
- Formatting with Correct Plurals
- Starting a Second Screen from the First
- Creating a Loading Screen That Will Appear Between Two Activities
- Using SlidingDrawer to Overlap Other Components
- Customizing the SlidingDrawer Component to Animate/Transition from the Top Down
- Adding a Border with Rounded Corners to a Layout
- Detecting Gestures in Android
- Building a UI Using Android 3.0 Fragments in Android 1.6 and Later
- Using the Android 3.0 Photo Gallery
- Creating a Simple App Widget
- Introduction: GUI Alerts
- Creating and Displaying a Menu
- Handling Choice Selection in a Menu
- Creating a Submenu
- Creating a Pop-up/Alert Dialog
- Using a Timepicker Widget
- Creating an iPhone-like Wheel Picker for Selection
- Creating a Tabbed Dialog
- Creating a ProgressDialog
- Creating a Custom Dialog with Buttons, Images, and Text
- Creating a Reusable About Box Class
- Customizing the Appearance of a Toast
- Creating a Notification in the Status Bar
- Introduction: ListView
- Building List-Based Applications with ListView
- Creating a “No Data” View for ListViews
- Creating an Advanced ListView with Images and Text
- Using Section Headers in ListViews
- Keeping the ListView with the User’s Focus
- Writing a Custom List Adapter
- Handling Orientation Changes: From ListView Data Values to Landscape Charting
- Introduction: Multimedia
- Playing a YouTube Video
- Using the Gallery with the ImageSwitcher View
- Capturing Video Using MediaRecorder
- Using Android’s Face Detection Capability
- Playing Audio from a File
- Playing Audio Without Interaction
- Using Speech to Text
- Making the Device Speak with Text-to-Speech
- Introduction: Data Persistence
- Getting File Information
- Reading a File Shipped with the App Rather Than in the Filesystem
- Listing a Directory
- Getting Total and Free Space Information About the SD Card
- Providing User Preference Activity with Minimal Effort
- Checking the Consistency of Default Shared Preferences
- Performing Advanced Text Searches
- Creating an SQLite Database in an Android Application
- Inserting Values into an SQLite Database
- Loading Values from an Existing SQLite Database
- Working with Dates in SQLite
- Parsing JSON Using JSONObject
- Parsing an XML Document Using the DOM API
- Parsing an XML Document Using an XmlPullParser
- Adding a Contact
- Reading Contact Data
- Introduction: Telephone Applications
- Doing Something When the Phone Rings
- Processing Outgoing Phone Calls
- Dialing the Phone
- Sending Single-Part or Multipart SMS Messages
- Receiving an SMS Message in an Android Application
- Using Emulator Controls to Send SMS Messages to the Emulator
- Using Android’s TelephonyManager to Obtain Device Information
- Introduction: Networking
- Using a RESTful Web Service
- Extracting Information from Unstructured Text Using Regular Expressions
- Parsing RSS/Atom Feeds Using ROME
- Using MD5 to Digest Clear Text
- Converting Text into Hyperlinks
- Accessing a Web Page Using WebView
- Customizing a WebView
- Introduction: Gaming and Animation
- Building an Android Game Using flixel-android
- Building an Android Game Using AndEngine (Android-Engine)
- Processing Timed Keyboard Input
- Introduction: Social Networking
- Integrating Social Networking Using HTTP
- Loading a User’s Twitter Timeline Using JSON
- Introduction: Location-Aware Applications
- Getting Location Information
- Accessing GPS Information in Your Application
- Mocking GPS Coordinates on a Device
- Using Geocoding and Reverse Geocoding
- Getting Ready for Google Maps Development
- Adding a Device’s Current Location to Google Maps
- Drawing a Location Marker on a Google MapView
- Drawing Multiple Location Markers on a MapView
- Creating Overlays for a Google MapView
- Changing Modes of a Google MapView
- Drawing an Overlay Icon Without Using a Drawable
- Implementing Location Search on Google Maps
- Placing a MapView Inside a TabView
- Handling a Long-Press in a MapView
- Using OpenStreetMap
- Creating Overlays in OpenStreetMap Maps
- Using a Scale on an OpenStreetMap Map
- Handling Touch Events on an OpenStreetMap Overlay
- Getting Location Updates with OpenStreetMap Maps
- Introduction: Sensors
- Checking for the Presence or Absence of a Sensor
- Using the Accelerometer to Detect Shaking of the Device
- Checking Whether a Device Is Facing Up or Facing Down Based on Screen Orientation Using an Accelerometer
- Finding the Orientation of an Android Device Using an Orientation Sensor
- Reading the Temperature Sensor
- Introduction: Bluetooth
- Enabling Bluetooth and Making the Device Discoverable
- Connecting to a Bluetooth-Enabled Device
- Listening for and Accepting Bluetooth Connection Requests
- Implementing Bluetooth Device Discovery
- Introduction: System and Device Control
- Accessing Phone Network/Connectivity Information
- Obtaining Information from the Manifest File
- Changing Incoming Call Notification to Silent, Vibrate, or Normal
- Copying Text and Getting Text from the Clipboard
- Using LED-Based Notifications
- Making the Device Vibrate
- Running Shell Commands from Your Application
- Determining Whether a Given Application Is Running
- Introduction: Other Programming Languages
- Running an External/Native Unix/Linux Command
- Running Native C/C++ Code with JNI on the NDK
- Getting Started with the Scripting Layer for Android (SL4A, Formerly Android Scripting Environment)
- Creating Alerts in SL4A
- Fetching Your Google Documents and Displaying Them in a ListView Using SL4A
- Sharing SL4A Scripts in QR Codes
- Using Native Handset Functionality from WebView via JavaScript
- Creating a Platform-Independent Application Using PhoneGap/Cordova
- Introduction: Internationalization
- Internationalizing Application Text
- Finding and Translating Strings
- Handling the Nuances of strings.xml
- Introduction: Packaging, Deploying, and Distributing
- Creating a Signing Certificate
- Signing Your Application
- Distributing Your Application via Android Play (formerly the Android Market)
- Integrating AdMob into Your App
- Obfuscating and Optimizing with ProGuard
- Providing a Link to Other Published Apps in the Google Play Market
- Colophon
Details of Ebook: Android Cookbook: Problems and Solutions for Android Developers
Title: Android Cookbook: Problems and Solutions for Android Developers
Author: Ian F. Darwin
ISBN: 9350237326
ISBN-13: 9789350237328,978-9350237328
File Type: RAR
File Size: 7.24 MB
Publishing Date: 2012
Publisher: Shroff/O'Reilly
Number of Pages: 704
Language: English