Android Application Development

Similar documents
Beginning Android 4 Application Development

ORACLE UNIVERSITY AUTHORISED EDUCATION PARTNER (WDP)

Android Programming (5 Days)

CorelDRAW X7. Kogent Learning Solutions Inc. Authored by: Published by:

Android" Application Development SAMS. Sams Teach Yourself. Shane Conder. Lauren Darcey. Second Edition

Course Learning Outcomes (CLO): Student Outcomes (SO):

Android App Development

MC Android Programming

ANDROID SYLLABUS. Advanced Android

Required Core Java for Android application development

Android Programming - Jelly Bean

Android Online Training

Syllabus- Java + Android. Java Fundamentals

ANDROID COURSE BROCHURE

Java Training Center - Android Application Development

Software Development & Education Center ANDROID. Application Development

Androidfp_printOnly.book Page vii Tuesday, October 4, :15 AM. Contents. Before You Begin

SUBJECT OUTLINE DETAILS

CHAPTER 1: HELLO, ANDROID 1

Android Apps Development

Android Syllabus. Android. Android Overview and History How it all get started. Why Android is different.

1. Implementation of Inheritance with objects, methods. 2. Implementing Interface in a simple java class. 3. To create java class with polymorphism

Android Essentials with Java

ATC Android Application Development

Pro Android 2. Sayed Y. Hashimi Satya Komatineni Dave Mac Lean. Apress

ANDROID TRAINING PROGRAM COURSE CONTENT

Android Training Overview (For Demo Classes Call Us )

Android Application Development

Course Syllabus. Course Title. Who should attend? Course Description. Android ( Level 1 )

Android Application Development using Kotlin

IGEEKS TECHNOLOGIES. Software Training Division. Academic Live Projects For BE,ME,MCA,BCA and PHD Students

ANDROID DEVELOPMENT. Course Details

Practical Problem: Create an Android app that having following layouts.

Building User Interface for Android Mobile Applications II

SEVEN ADVANCED ACADEMY

ANDROID APPLICATION DEVELOPMENT PROSPECTUS ADAAD UNIVERSITY OF SKILLS

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

Android Application Development Course Code: AND-401 Version 7 Duration: 05 days

XAMARIN Application Development - Workshop

CS378 -Mobile Computing. What's Next?

android application development CONTENTS 1.1 INTRODUCTION TO O ANDROID OPERATING SYSTEM... TURES Understanding the Android Software Stack...

Android Application Development 101. Jason Chen Google I/O 2008

CS 4518 Mobile and Ubiquitous Computing Lecture 5: Data-Driven Views and Android Components Emmanuel Agu

SHWETANK KUMAR GUPTA Only For Education Purpose

Answers to Exercises

Android App Development

B. V. Patel Institute of Business Management, Computer & Information Technology, UTU

GUJARAT TECHNOLOGICAL UNIVERSITY

Android Programming in Bluetooth Cochlea Group

CS371m - Mobile Computing. More UI Action Bar, Navigation, and Fragments

LECTURE 08 UI AND EVENT HANDLING

In this Class Mark shows you how to put applications into packages and how to run them through the command line.

Questions and Answers. Q.1) Which of the following is the most ^aeuroeresource hungry ^aeuroepart of dealing with activities on android?

Mobile Application Development

CS 4518 Mobile and Ubiquitous Computing Lecture 4: Data-Driven Views, Android Components & Android Activity Lifecycle Emmanuel Agu

Android Application Development Course 28 Contact Hours

ANDROID APPS DEVELOPMENT FOR MOBILE GAME

CS371m - Mobile Computing. More UI Navigation, Fragments, and App / Action Bars

CS 4518 Mobile and Ubiquitous Computing Lecture 2: Introduction to Android Programming. Emmanuel Agu

MARS AREA SCHOOL DISTRICT Curriculum TECHNOLOGY EDUCATION

Android. Lesson 1. Introduction. Android Developer Fundamentals. Android Developer Fundamentals. to Android 1

Introduction to Android

Contextual Android Education

Programming Android UI. J. Serrat Software Design December 2017

CS 528 Mobile and Ubiquitous Computing Lecture 2a: Introduction to Android Programming. Emmanuel Agu

Android Overview. Most of the material in this section comes from

Android System Architecture. Android Application Fundamentals. Applications in Android. Apps in the Android OS. Program Model 8/31/2015

Programming in Android. Nick Bopp

ANDROID APPS (NOW WITH JELLY BEANS!) Jordan Jozwiak November 11, 2012

Oracle Mobile Application Framework

Android Apps Development

CS378 -Mobile Computing. User Interface Basics

Static analysis for quality mobile applications

BCA 6. Question Bank

Mumbai Android Bootcamp -Course Content

Copyright and Trademark Information Trademarks Disclaimer; No Warranty

Mobile Application Development Android

Mobile Programming Lecture 1. Getting Started

Topics Covered in the Android Apps Development Training

PART I: INTRODUCTION TO WINDOWS 8 APPLICATION DEVELOPMENT CHAPTER 1: A BRIEF HISTORY OF WINDOWS APPLICATION DEVELOPMENT 3

Praktikum Entwicklung Mediensysteme. Implementing a User Interface

IBM Datacap Mobile SDK Developer s Guide

Following are some questions asked during the developer day,conducted on 16 th Sep 2011 at Bangalore, India.

OCTOSHAPE SDK AND CLIENT LICENSE AGREEMENT (SCLA)

Preface...3 Acknowledgments...4. Contents...5. List of Figures...17

LTBP INDUSTRIAL TRAINING INSTITUTE

Android Development Crash Course

This guide describes features that are common to most models. Some features may not be available on your tablet.

COURSE SYLLABUS ANDROID. Industrial Training (4 MONTHS) PH : , Vazhoor Road Changanacherry-01.

Mobile OS. Symbian. BlackBerry. ios. Window mobile. Android

Upgrading BankLink Books

CORE JAVA& ANDROID SYLLABUS

Xperia TM. in Business. Product overview. Read about the enterprise policies and features supported in Xperia devices.

LEGITIMATE APPLICATIONS OF PEER-TO-PEER NETWORKS

Jim Jackson II Ian Gilman

CS 528 Mobile and Ubiquitous Computing Lecture 2a: Android UI Design in XML + Examples. Emmanuel Agu

Beginning Android Tablet

Qt for Device Creation

Introduction To Android

Android Basics Nanodegree Syllabus

Transcription:

Android Application Development (upto Android 4.4) Black Book TM Kogent Learning Solutions Inc. Published by:

Copyright 2014 by Dreamtech Press, 19-A, Ansari Road, Daryaganj, New Delhi-110002 Black Book is a trademark of Paraglyph Press Inc., 2246 E. Myrtle Avenue, Phoenix Arizona 85202, USA exclusively licensed in Indian, Asian and African continent to Dreamtech Press, India. This book may not be duplicated in any way without the express written consent of the publisher, except in the form of brief excerpts or quotations for the purposes of review. The information contained herein is for the personal use of the reader and may not be incorporated in any commercial programs, rams, other books, databases, or any kind of software without written consent of the publisher. Making copies of this book or any portion for any purpose other than your own is a violation of copyright laws. Limits of Liability/disclaimer laimer of Warranty: The author and publisher have used their best efforts in preparing ring this book. The author make no representation or warranties with respect to the accuracy acy or completeness ess of the contents of this book, and specifically disclaim any implied ied warranties of merchantability or fitness of any particular purpose. There are no warranties which extend end beyond the descriptions contained in this paragraph. No warranty may be created or extended by sales representatives or written sales materials. The accuracy cy and completeness of the information provided herein and the opinions stated herein ein are not guaranteed or warranted to produce any particulars results, and the advice and strategies contained herein may not be suitable for every individual. Neither Dreamtech Press nor author shall be liable for any loss of profit or any other commercial cial damages, including but not limited to special, incidental, consequential, or other damages. Trademarks: All brand names and product names used in this book are trademarks, registered trademarks, or trade names of their respective holders. Dreamtech Press is not associated with any product or vendor mentioned in this book. ISBN: 978-93-5119-409-5 Edition: 2014 Printed at: Himal Impressions, Delhi

Dedication I would like to dedicate this book to my parents Mr Radha Krishan Kothari and Mrs Vijay Laxmi, without whom my life would not have any meaning. Thank you so much for all your unconditional support, love, and education. Everything I am, I owe to my parents. DREAM M TECH

About the Author Pradeep Kothari holds the B.E. degree in Electronics and Communication and has about 9 years of industry experience in developing, architecting, ting, and deploying enterprise-level mobile technological product and solutions for Windows mobile, J2ME, Android, and iosbased devices while working in some top technology companies in the domain of Telecom, Gaming, Mobile content solutions, and Education technology. Pradeep started his software carrier writing Mobile apps for Pocket PC 2003 (early version of windows mobile) in the early days of evolution of smart phones. He then progressed to Android and ios programming for handled devices. He also provided consulting to some top technology companies like Lionbridge Inc. and Microsoft Learning. Currently, he is a Ph.D. researcher in the field of mobility and a Technical Manager with a technology company, where he is leading a team in designing and developing cutting edge enterprise mobile products for mobile phones as well as tablets. DREAM

Contents at a Glance Introduction... Chapter 1: Getting an Overview of Android... 1 Chapter 2: Working with the Activities and Intents in Android... 31 Chapter 3: Working with the User Interface Using Views and ViewGroups... 87 Chapter 4: Handling Pictures and Menus with Views...157 Chapter 5: Storing the Data a Persistently...183 Chapter 6: Networking and E-mailing in Android...233 Chapter 7: Working with Location on Services and Maps...257 Chapter 8: Working with Graphics and Animation...283 Chapter 9: Audio, Video, and Using the Camera...315 Chapter 10: Thread and Services...349 Chapter 11: Bluetooth, NFC, and Wi-Fi...371 Chapter 12: Telephony and SMS...401 Chapter 13: Hardware Sensors...427 Chapter 14: Widgets and Live Wallpapers in Android...441 Chapter 15: Developing NDK Applications...461

Contents at a Glance Chapter 16: Developing, Monetizing, Promoting, and Publishing Android Applications...481 Glossary...505 Index... Online Resource Available with the Book... Bonus Chapters Available with the Book Appendix A: Fundamentals of Java for Android Application Development Appendix B: Getting Started with Android Studio New IDE for Development by Google Appendix C: Introducing Tasker vi

Introduction..... xv Chapter 1: Getting an Overview of Android... 1 Introducing Android... 2 Listing the Version History of Android Platform... 2 Discussing Android APIs... 3 Describing the Android Architecture... 4 Application Framework... 5 Exploring the Features of Android... 6 Discussing about Android Applications... 6 The Application Components nts... 6 The Manifest File... 7 Downloading and Installing Android... 7 Downloading and Installing the Android SDK... 7 Setting up Android Virtual Device... 11 Setting up Android d Physical Device... 13 Exploring the Development ent Environment nm... 15 The Java Perspective Using Eclipse... 15 The DDMS Perspective... 15 The Command-Line Tools... 15 Developing and Executing the First Android Application... 18 Using Eclipse IDE to Create an Application... 18 Running Your Application... 20 Exploring the Application... 22 Using Command-Line Tools... 26 Summary... 27 Quick Revise... 27 Chapter 2: Using Activities, Fragments, and Intents in Android... 31 Working with Activities... 32 Creating an Activity... 32

Starting an Activity... 34 Managing the Lifecycle of an Activity... 39 Applying Themes and Styles to an Activity... 42 Displaying a Dialog in the Activity... 44 Hiding the Title of the Activity... 56 Using Intents... 57 Exploring Intent Objects... 57 Exploring Intent Resolution... 60 Exploring Intent Filters... 61 Resolving Intent Filter Collision... 62 Linking the Activities Using Intent... 62 Obtaining Results from Intent... 67 Passing Data Using an Intent Object... 71 Fragments... 75 Fragment Implementation... 76 Finding Fragments... 77 Adding, Removing, and Replacing Fragments... 77 Finding Activity Using Fragment... 78 Using the Intent Object to Invoke Built-in in Application... 78 Summary... 81 Quick Revise... 81 Chapter 3: Working with the User Interface Using Views and ViewGroups... 87 Working with View Groups... 88 The LinearLayout Layout... 91 The RelativeLayout ayout Layout... 95 The ScrollView Layout... 97 The TableLayout Layout... 99 The FrameLayout Layout... 101 The TabLayout Using the Action Bar... 102 Working with Views... 106 Using the TextView... 111 Using the EditText View... 112 Using the Button View... 113 Using the RadioButton View... 115 Using the CheckBox View... 118 Using the ImageButton View... 120 Using the ToggleButton View... 122 Using the RatingBar View... 124 Binding Data with the AdapterView Class... 126 Using the ListView Class... 126

Using the Spinner... 127 Using the Gallery View... 130 Designing the AutoTextCompleteView... 131 Implementing Screen Orientation... 133 Anchoring the Views of the Current Activity... 134 Customizing the Size and Position of the Views... 134 Designing the Views Programmatically... 134 Handling UI Events... 136 Handling User Interaction with Activities... 136 Handling User Interaction with the Views... 138 Specialized Fragments... 139 ListFragment... 139 DialogFragment... 141 PreferenceFragment... 143 Creating Menus... 145 The Options Menu... 145 The Context Menu... 147 The SubMenus... 150 Summary... 150 Quick Revise... 151 Chapter 4: Handling Pictures and Menus with Views... 157 Working with Image Views... 158 Displaying Images in the Gallery View... 158 Displaying Images in the Grid View... 164 Using the ImageSwitcher e View... 166 Designing Context Menu for Image View... 169 Using the AnalogClock and DigitalClock Views... 172 COP PYRIGHT Embedding Web Browser in an Activity... 176 Notifying the User... 178 Creating the Toast Notification... 178 Creating the Status Bar Notification... 179 Creating the Dialog Notification... 180 Summary... 180 Quick Revise... 180 Chapter 5: Storing the Data Persistently... 183 Introducing the Data Storage Options... 184 Using Preferences... 184 Using the Internal Storage... 187 Exploring the Methods Used for Internal Storage... 188 x

Developing an Application to Save User Data Persistently in File... 189 Using the External Storage... 193 Exploring the Methods Used for External Storage... 193 Developing Application to Save File in SD Card... 194 Using the SQLite Database... 197 Creating the Database Helper Class... 197 Creating the Layout and Main Activity Class... 200 Creating the Layout and Activity for the Insert Operation... 203 Creating the Layout and Activity to Search a Record... 204 Creating the Activity Class to Fetch All Records... 206 Creating the Layout and Activity for the Update Operation... 207 Creating the Layout and Activity for the Delete Operation... 209 Executing the Database Operations... 211 Working with Content Providers... 216 Exploring the android.provider Package... 217 Creating User-Defined Content Provider... 220 Consuming User-Defined Content Provider... 225 Summary... 228 Quick Revise... 228 Chapter 6: Emailing and Networking in Android... 233 Building an Application to Send Email... 234 Networking in Android... 237 Getting an Overview of Networking Fundamentals... 237 Checking Network Availability... 237 Accessing Web Services Using HTTP Post... 238 Accessing Web Services Using the GET Method... 241 Working with Binary Data a and Text Files... 244 Consuming JSON Services es... 247 Sockets Programming... 250 Summary... 255 Quick Revise... 255 Chapter 7: Working with Location Services and Maps... 257 x Working with Google Maps... 258 Exploring Google Maps External Library... 258 Creating an Application Using Google Maps Android API... 258 Disabling the Zoom Control Button... 266 Changing the Map Type... 267 Displaying the Specific Location and Adding Markers... 269 Handling Map Gestures Interaction... 272

Getting the Current Location of a User... 272 Working with Geocoding and Reverse Geocoding... 276 Summary... 280 Quick Revise... 280 Chapter 8: Working with Graphics and Animation... 283 Working with Graphics... 284 Drawing Graphics to Canvas... 284 Using the Drawable Object... 290 Referencing an Image File... 291 Defining Drawable in XML... 292 Using the ShapeDrawable Object... 294 Working with the NinePatchDrawable Graphics... 297 Understanding the Concept of Hardware Acceleration... 299 Working with Animations... 300 The Property Animation.... 300 View Animation... 303 Drawable Animation... 305 Summary... 306 Quick Revise... 306 Chapter 9: Audio, Video, and Camera... 315 Role of Media Playback... 316 Using Media Player... 316 Media Formats Supported by Media Player... 316 Preparing Audio for Playback ack... 317 Preparing Video for Playback ack... 318 Creating Application to Play Audio and Video Using MediaPlayer... 319 Recording and Playing Sound... 328 Use of Media Store... 329 Audio Recording Application... 329 Creating a Sound Pool... 334 Using Camera for Taking Pictures... 336 Recording Video... 340 Creating Video Recording Application... 341 Summary... 345 Quick Revise... 345 xi

Chapter 10: Threads and Services... 349 Introducing Threads... 350 Worker Threads... 350 Using AsyncTask... 352 Introducing Services... 355 Exploring Services Essentials... 355 Understanding the Lifecycle of a Service... 356 Exploring the Service Class... 357 Introducing the Service Class... 357 Creating a Bound Service... 363 Summary... 368 Quick Revise... 368 Chapter 11: Bluetooth, NFC, and Wi-Fi... 371 Working with Bluetooth... 372 Exploring the Android Bluetooth APIs... 372 Permissions Required to Access Bluetooth... 374 Setting Up the Bluetooth for an Application... 374 Identifying the Bluetooth-Enabled Devices... 375 Querying the Paired Devices... 375 Discovering Devices... 375 Creating an Application Using Bluetooth Functionality... 376 Connecting the Devices Using Bluetooth th for Data Transfer... 382 Connecting as a Server... 382 Connecting as a Client... 384 Working with Bluetooth Low Energy... 387 Working with NFC... 388 Exploring the Basics of NFC C...... 388 Developing an Application Using NFC... 390 Working with Wi-Fi... 393 Exploring the Wi-Fi APIs... 394 Creating an Application Using Wi-Fi... 396 Summary... 400 Quick Revise... 400 Chapter 12: Telephony and SMS... 385 Handling Telephony... 404 Displaying Phone Information Application... 407 Receiving Phone Calls Application... 409 xi

Making Outgoing Phone Calls Application... 411 Handling SMS... 414 Sending SMS Using SmsManager... 414 Sending SMS Using Intent... 417 Receiving SMS Using the BroadcastReceiver Object... 421 Role of Default SMS Providers... 422 Summary... 424 Quick Revise... 424 Chapter 13: Hardware Sensors... 427 Introducing Sensors... 428 Exploring the Sensor Framework... 429 Managing Various Sensor Configurations... 432 Understanding the Sensor Coordinate System... 433 Using Sensors... 433 Summary... 439 Quick Revise... 439 Chapter 14: Widgets and Live Wallpapers apers in Android... 441 Home Screen Widgets... 442 Adding the Broadcast Receiver Class to an Android d Manifest... 443 Using the RemoteViews and AppWidgetManager ger Classes... 444 Creating a Customized Clock Widget... 444 Collection View Widgets... 448 Collection View Widget Layouts... 449 Creating the Remote Views Service Class... 449 Creating a Remote Views Factory Interface... 450 Populating Collection View Widgets... 451 Live Wallpaper... 451 Creating Live Wallpaper Resource and Service... 451 Configuring Wallpaper Service... 452 Creating Live Wallpaper Application... 452 Summary... 457 Quick Revise... 457 Chapter 15: Working with NDK... 461 Introducing NDK... 462 When to Use NDK?... 462 Benefits of NDK... 462 Communication between Java and Native Code... 462 Installing the NDK... 463 x

Installing C/C++ Support on Eclipse... 463 Installing NDK Plugin through ADT... 465 Installing Cygwin... 466 Installing Android NDK... 469 Configuring Eclipse for NDK Programming... 470 Setting the Environment Variable... 471 Building the Basic NDK Application... 473 Summary... 478 Quick Revise... 478 Chapter 16: Implementing JBoss Seam... 481 Signing the Android Application... 482 Exploring the Strategies for Signing the Application... 482 Obtaining the Appropriate Private Key... 483 Preparing the Application for Release... 486 Aligning the APK Package... 486 Signing and Aligning APK Using the Eclipse IDE... 487 Versioning the Android Application... 489 Setting the Application Version... 489 Specifying API Requirements of an Android Application... 490 Publishing the Android Application ion... 490 Releasing Applications on Google ogle Play... 491 Releasing Applications through Email... 495 Releasing Applications through a Website... 495 Monetizing Applications... 495 Monetizing an Application through Advertising Platform... 496 Integrating the Google ogle AdMob SDK with an Application... 497 Summary... 501 CO OPYRIGHT Quick Revise... 501 Glossary... 505 Index... Online Resource Available with the Book... Bonus Chapters Available with the Book Appendix A: Fundamentals of Java for Android Application Development Appendix B: Getting Started with Android Studio New IDE for Development by Google Appendix C: Introducing Tasker x v