Android in Action. Second Edition. Revised Edition of Unlocking Android MANNING. (74 w. long.) W. FRANK ABLESON CHRIS KING ROBI SEN.



Similar documents
Android Application Development. Daniel Switkin Senior Software Engineer, Google Inc.

Mobility Introduction Android. Duration 16 Working days Start Date 1 st Oct 2013

Introduction to Android

Android (Basic + Advance) Application Development

«compl*tc IDIOT'S GUIDE. Android App. Development. by Christopher Froehlich ALPHA. A member of Penguin Group (USA) Inc.

Getting Started with Android Programming (5 days) with Android 4.3 Jelly Bean

ANDROID INTRODUCTION TO ANDROID

Table of Contents. Adding Build Targets to the SDK 8 The Android Developer Tools (ADT) Plug-in for Eclipse 9

An Introduction to Android Application Development. Serdar Akın, Haluk Tüfekçi

Here to take you beyond Mobile Application development using Android Course details

CHAPTER 1: INTRODUCTION TO ANDROID, MOBILE DEVICES, AND THE MARKETPLACE

Google Android Syllabus

ITG Software Engineering

Developer's Cookbook. Building Applications with. The Android. the Android SDK. A Addison-Wesley. James Steele Nelson To

Overview of CS 282 & Android

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

Module Title: Software Development A: Mobile Application Development

UNIVERSITY AUTHORISED EDUCATION PARTNER (WDP)

COURSE CONTENT. GETTING STARTED Select Android Version Create RUN Configuration Create Your First Android Activity List of basic sample programs

INTERMEDIATE ANDROID DEVELOPMENT Course Syllabus

Practical Android Projects Lucas Jordan Pieter Greyling

Android Basics. Xin Yang

Workshop on Android and Applications Development

4 Application Development

Getting started with Android and App Engine

Des Moines Area Community College

An Introduction to Android

Lecture 1 Introduction to Android

Introduction to Android Android Architecture Software Development Purpose of the project Location Based Service (LBS) Android. Location class Google

Android Development Tutorial. Nikhil Yadav CSE40816/ Pervasive Health Fall 2011

Introduction to Oracle Mobile Application Framework Raghu Srinivasan, Director Development Mobile and Cloud Development Tools Oracle

Development. SriSeshaa Technologies. Table of Contents

Android Application Development

Creating and Using Databases for Android Applications

Graduate presentation for CSCI By Janakiram Vantipalli ( Janakiram.vantipalli@colorado.edu )

Overview. The Android operating system is like a cake consisting of various layers.

ANDROID BASED MOBILE APPLICATION DEVELOPMENT and its SECURITY

Introduction to Android

1. Introduction to Android

Introduction to Android Development. Jeff Avery CS349, Mar 2013

Android Development. Lecture AD 0 Android SDK & Development Environment. Università degli Studi di Parma. Mobile Application Development

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

Introduction to Tizen SDK Alpha. Taiho Choi Samsung Electronics

A Short Introduction to Android

Android Application Development - Exam Sample

Android Developer Fundamental 1

Android Architecture. Alexandra Harrison & Jake Saxton

Mobile Phones Operating Systems

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

An Introduction to Android. Huang Xuguang Database Lab. Inha University

Location-Based Information Systems

Introduction to BlackBerry Smartphone Web Development Widgets

Introduction to Android

ANDROID PROGRAMMING - INTRODUCTION. Roberto Beraldi

Priority Based Pre-emptive Task Scheduling for Android Operating System

3. Software Installation. 4. Introduction to Android OS. 5. Using Android OS / Devices. 6. Eclipse debug with Android app. 8. Units of measurement

Introduction to Android: Hello, Android! 26 Mar 2010 CMPT166 Dr. Sean Ho Trinity Western University

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

CS378 -Mobile Computing. Android Overview and Android Development Environment

Технологии Java. Android: Введение. Кузнецов Андрей Николаевич. Санкт-Петербургский Государственный Политехнический Университет

CS 528 Mobile and Ubiquitous Computing Lecture 2: Android Introduction and Setup. Emmanuel Agu

Open Source Telemedicine Android Client Development Introduction

An Android-based Instant Message Application

ANDROID PROGRAMMING - INTRODUCTION. Roberto Beraldi

JavaScript Programming

Jordan Jozwiak November 13, 2011

ORACLE MOBILE APPLICATION FRAMEWORK DATA SHEET

Q1. What method you should override to use Android menu system?

BogDan Vatra and Andy Gryc. Qt on Android: Is it right for you?

Mobilize Your ERP with ADF Mobile

JavaFX Session Agenda

Android Development Exercises Version Hands On Exercises for. Android Development. v

QML and JavaScript for Native App Development

Beginning Android Programming

ANDROID APP DEVELOPMENT: AN INTRODUCTION CSCI /19/14 HANNAH MILLER

Programming with Android: System Architecture. Dipartimento di Scienze dell Informazione Università di Bologna

Junos Space for Android: Manage Your Network on the Go

ECE 455/555 Embedded System Design. Android Programming. Wei Gao. Fall

Hacking your Droid ADITYA GUPTA

DESIGNING AN M-LEARNING APPLICATION FOR A UBIQUITOUS LEARNING ENVIRONMENT IN THE ANDROID BASED MOBILE DEVICES USING WEB SERVICES

Building an Android client. Rohit Nayak Talentica Software

Android Geek Night. Application framework

Smartphone Enterprise Application Integration

City of Dublin Education & Training Board. Programme Module for. Mobile Technologies. leading to. Level 6 FETAC. Mobile Technologies 6N0734

DEVELOPING MOBILE APPLICATIONS USING ANDROID

Homeschool Programming, Inc.

INTRODUCTION TO ANDROID CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 11 02/15/2011

Deep Inside Android. OpenExpo Zurich September 25 th, Gilles Printemps - Senior Architect. Copyright 2007 Esmertec AG.

ORACLE ADF MOBILE DATA SHEET

Professional Tizen Application Development

Introduction to Android. CSG250 Wireless Networks Fall, 2008

Mobile App Design and Development

Application Development

Android Application Development

Android Operating System

Safe Harbor Statement

How To Develop Android On Your Computer Or Tablet Or Phone

Transcription:

Android in Action Second Edition W. FRANK ABLESON ROBI SEN CHRIS KING Revised Edition of Unlocking Android II MANNING Greenwich (74 w. long.)

contents preface xvii preface to the first edition xix acknowledgments xxi about this book xxiv about the cover illustration xxix Part 1 What is Android? The Big Picture...1 Introducing Android 3 1.1 The Android platform 4 1.2 Understanding the Android market 5 Mobile operators 5 Android vs. the feature phones 6 Android vs. the smartphones 7 Android vs. itself 8 Licensing Android 9 1.3 The layers ofandroid 10 Building on the Linux kernel 11 Running in the DalvikVM 12 1.4 The Intent of Android development 12 Empowering intuitive UIs 13 Intents and how they work 13 vii

viii CONTENTS 1.5 Four kinds ofandroid components 17 Activity 17 * Service 18 * BroadcastReceiver 19 ContentProvider 22 1.6 Understanding the AndroidManifestxml file 24 1.7 Mapping applications to processes 25 1.8 Creating an Android application 26 1.9 Summary 30 Android's development environment 31 2.1 Introducing the Android SDK 32 Care Androidpackages 33 Optionalpackages 34 2.2 Exploring the development environment 34 The Java perspective 35 The DDMS perspective 37 Command-line tools 40 2.3 Building an Android application in Eclipse 43 TheAndroid Project Wizard 43 * Android sample application code 44 * Packaging the application 50 2.4 Using the Android emulator 51 Setting up the emulated environment 52 Testingyour application in the emulator 56 2.5 Debugging your application 57 2.6 Summary 58 Part 2 Exercising the Android SDK 61 User interfaces 63 3.1 Creating the Activity 65 Creating an Activity class 66 Exploring the Activity lifecycle 71 3.2 Working with views 74 Exploring common views 75 Using a ListView 77 Multitasking with Handler and Message 81 Creating custom views 82 Understanding layout 84 Handlingfocus 86 Grasping events 87 3.3 Using resources 89 Supported resource types 89 «Referencing resources in Java 89 Defining views and layouts through XML resources 92 Externalizing values 94 Providing animations 97

3.4 Exploring the AndroidManifest file 98 3.5 Summary 99 Intents and Services 101 4.1 Serving up RestaurantFinder with Intent 102 Defining Intents 102 Implicit and explicit invocation 103 Adding external links to RestaurantFinder 104 Finding your way with Intent 106* Taking advantage of Androidrprovided activities 108 4.2 Checking the weather with a custom URI 109 Offering a custom URI 109 Inspecting a custom Uri 111 4.3 Checking the weather with broadcast receivers 113 Broadcasting Intent 113 «Creating a receiver 115 4.4 Building a background weather service 115 4.5 Communicating with the WeatherAlertService from other apps 119 Android Interface Definition Language 119 Binder and Parcelable 121 * Exposing a remote interface 122 Binding to a Service 123 * Starting versus binding 126 Service lifecycle 127 4.6 Summary 128 Storing and retrieving data 129 5.1 Using preferences 130 Working with SharedPreferences 130 Preference access permissions 133 5.2 Using the filesystem 136 Creatingfiles 136 Accessingfiles 137 Files as raw resources 138 XML file resources 139 External storage via an SD card 141 5.3 Persisting data to a database 144 5.4 Working Building and accessing a database 144 Using the sqlite3 tool 149 with ContentProvider classes 149 Using an existing ContentProvider 150 Creating a ContentProvider 151 5.5 Summary 158

Networking and web services 159 6.1 An overview of networking 161 Networking basics 161 Clients and servers 163 6.2 Checking the network status 164 6.3 Communicating with a server socket 165 6.4 Working with HTTP 168 Simple HTTP and java.net 169 «Robust HTTP with HttpClient 170 * Creating an HTTP and HTTPS helper 172 6.5 Web services 178 POX Putting it together with HTTP and XML 179 REST 181 To SOAP or not to SOAP, that is the question 184 6.6 Summary 185 Telephony 187 7.1 Exploring telephony background and terms 188 Understanding GSM 189* Understanding CDMA 189 7.2 Accessing telephony information 190 Retrieving telephony properties 191 Obtaining phone state information 193 7.3 Interacting with the phone 195 Using intents to make calls 195* utilities 196 Intercepting outbound calls 198 7.4 Working with messaging: SMS 199 Using phone number-related Sending SMS messages 199 Receiving SMS messages 202 7.5 Summary 203 Notifications 8.1 Introducing and alarms 205 Toast 206 Creating an SMS example with a Toast 206 * Receiving an SMS message 207 8.2 Introducing notifications 210 The Notification class 210 * Notifying a user ofan SMS 211 8.3 Introducing Alarms 215 Creating a simple alarm example 215» Using notifications with Alarms 218 8.4 Summary 220

Graphics and animation 222 9.1 Drawing graphics in Android 223 Drawing with XML 224 * Exploring XML drawable shapes 225 9.2 Creating animations with Android's Graphics API 22V Android's frame-by-frame animation 227 * Programmatically an creating animation 230 9.3 Introducing OpenGL for Embedded Systems 233 Creating an OpenGL context 234 Drawing a rectangle with OpenGL ES 238 «Three-dimensional shapes and surfaces with OpenGL ES 241 9.4 Summary 245 Multimedia 246 10.1 Introduction to multimedia and OpenCORE 247 10.2 Playing audio 248 10.3 Playing video 250 10.4 Capturing media 251 Understanding the camera 252 Capturing audio 257 10.5 Recording video 259 10.6 Summary 265 Location, location, location 267 11.1 Simulating your location within the emulator 269 Sending in your coordinates with theddms tool 269 The GPS Exchange Format Keyhole Markup Language 2 72 271' The Google Earth 11.2 Using LocationManager and LocationProvider 275 Accessing location data with LocationManager 275 Using a LocationProvider 277 * Receiving location updates with LocationListener 279 11.3 Working with maps 281 Extending MapActivity 282 Using a MapView 282 Placing data on a map with an Overlay 285 11.4 Converting places and addresses with Geocoder 288 11.5 Summary 290

xii CONTENTS Part 3 Android applications..2 Putting Android to work in afield service application 293 12.1 Designing a real-world Android application 294 Core requirements of the application 295 * Managing the data 296 * Application architecture and integration 297 12.2 Mapping out the application flow 298 Mapping out the field service application 298 * List of source files 300 * Field service application'sandroidmanifest.xml 302 12.3 Application source code 302 Splash Activity 302 * Preferences used by the FieldService Activity 304 * Implementing the FieldService Activity 306 Settings 307 Managingjob * data 309 12.4 Source code for managingjobs 316 Refreshjobs 317 * Managing jobs: The Managejobs Activity 320 * Working with a job with the Showjob Activity 323 Capturing a signature with the Closejob Activity 327 12.5 Server code 333 Dispatcher user interface 334 * Database 334 * PHP dispatcher code 335 * PHP mobile integration code 336 12.6 Summary 337 Building Android applications in C 338 13.1 Building Android apps without the SDK 339 The C compiler and linker tools 339 * Building a Hello World application 340 * Installing and running the application 342 C application build script 344 13.2 Solving the problem with dynamic linking 344 Android system libraries 345 * Building a dynamically linked application 346 * exitq versus returnq 349 * Startup code 350 13.3 What time is it? The DayTime Server 352 13.4 Daytime DayTime Server application 352 daytime.c 353 The SQLite database 355 * Building and running the DayTime Server 358 Client 360 Activity 360 * Socket Client 361 * Testing the Daytime Client 362 13.5 Summary 362

xiii Part 4 The maturing platform..365 Bluetooth and sensors 367 14.1 Exploring Android's Bluetooth capabilities 368 Replacing cables 369 Primary and secondary roles and sockets 369 > Trusting a device 370 Connecting to a remote device 372 * Capturing Bluetooth events 374 Bluetooth permissions 375 14.2 Interacting with the SensorManager 375 Types of 'sensors 376 * Reading sensor values 377 Enabling and disabling sensors 3 78 14.3 Building the SenseBot application 379 User interface 380 Interpreting sensor values 382 Driving the robot 383 Communication with the robot 384 14.4 Summary 385 Integration 387 15.1 Understanding the Android contact model 388 15.2 Getting Choosing open-ended records 388 Dealing with multiple accounts 390 Unifying a local view from diverse remote stores 392 Sharing the playground 393 started with Linkedln 393 15.3 Managing contacts 395 Leveraging the built-in contacts app 395 * Requesting operations from your app 398 «Directly reading and modifying the contacts database 399 Adding contacts 400 15.4 Keeping it together 403 15.5 Creating The dream of sync 403 Defining accounts 404 Telling secrets: The AccountManagerservice 405 a Linkedln account 406 Not friendly to mobile 406 Authenticating to Linkedln 407 15.6 Synchronizing to the backend with SyncAdapter 414 The synchronizing lifecycle 414 Synchronizing Linkedln data 414 15.7 Wrapping up: Linkedln in action 417 Finalizing the Linkedln project 417 Troubleshooting tips 418 on Moving 419 15.8 Summary 419

Android web development 421 16.1 What's Android web development? 422 Introducing WebK.it 422 Examining the architectural options 423 16.2 Optimizing web applications for Android 424 Designing with mobile in mind 424 Adding the viewport tag 426 Selectively loading content 428 Interrogating the user agent 428 The media query 429 * Considering a madefor-mobile application 430 16.3 Storing data directly in the browser 431 Setting things up 432 Examining the * code 433 The user interface 433 Opening the database 435 Unpacking the transactionfunction 436 Inserting and deleting rows 438 Testing the application with WebKit tools 439 16.4 Building a hybrid application 440 Examining the browser control 440 Wiring up the control 441 Implementing the JavaScript handler 443 * Accessing the code fromjavascript 445 Digging into the JavaScript 445 Security matters 447 Implementing a WebViewClient 448 Augmenting the browser 448 Detecting navigation Implementing the WebChromeClient 452 16.5 Summary 453 events 449 AppWidgets 454 17.1 Introducing the AppWidget 455 What's an AppWidgets 455 AppWidget deployment strategies 457 17.2 Introducing SiteMonitor 458 Benefits of SiteMonitor 458 «The user experience 459 17.3 SiteMonitor application architecture 462 Bird's-eye view of the application 462 File by file 464 17.4 AppWidget data handling 465 17.5 Implementing the AppWidgetProvider 469 AppWidgetProvider method inventory 469 Implementing SiteMonitorWidgetlmpl 470 1 Handling zombie widgets 472 17.6 Displaying an AppWidget with RemoteViews 473 Working with RemoteViews 473 * UpdateOneWidget explained 474

XV 17.7 Configuring an instance of the AppWidget 476 AppWidget metadata 477 Working with Intent data 478 Confirming widget creation 479 17.8 Updating the AppWidget 480 Comparing services to alarms 481 Triggering the update 482 Updating the widgets, finally! 484 17.9 Tying it all together with AndroidManifest.xml 488 17.10 Summary 489 Localization 491 18.1 The need for localization 492 18.2 Exploring locales 493 18.3 Strategies for localizing an application 494 Identifying target locales and data 494 Identifying and «managing strings 495 Drawables and layouts 497 Dates, times, numbers, and currencies 498 Working with the translation team 499 18.4 Leveraging Android resource capabilities 500 More than locale 500 «Assigning strings in resources 500 18.5 Localizing in Java code 502 18.6 Formatting localized strings 503 18.7 Obstacles to localization 504 18.8 Summary 505 Android Native Development Kit 506 19.1 Introducing the NDK 507 Uses for the NDK 507 - Looking at the NDK 508 19.2 Building an application with the NDK 509 Demonstrating the completed application 510 Examining the project structure 511 19.3 Building the JNI library 512 19.4 Building UnderstandingJNI 512 Implementing the library 513 Compiling thejni library 518 the user interface 519 User interface layout 519* Taking a photo 521 Finding the edges 523

xvi CONTENTS 19.5 Integrating the NDK into Eclipse 524 19.6 Summary 526 appendix A Installing the Android SDK 527 appendix B Publishing applications 538 index 551