By Chau Ngo EEL 6788- Advanced Topics in Wireless Networks

y Android application development overview y Getting started

y Background information y Creating development environment y ³Hello, Android´ tutorial/demo y Install/Debug application on Android phone device y ³Sensors´ API sample demo

What is Android?
y Android is a software stack for mobile devices that includes an operating

system, middleware, and key applications.

y Android Software Development Kit (SDK) Provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.
Includes a debugger, libraries, a handset emulator (based on QEMU), documentation, sample code, and tutorials

y Android Market is an online software store developed by Google for Android


An application program ("app") called "Market" is preinstalled on most Android devices and allows users to browse and download apps published by third-party developers, hosted on Android Market As of December 2010, the Android Market had over 200,000 applications

y Android mobile operating system initially developed by

Android Inc, based in Palo Alto, CA. y Android's co-founders

Andy Rubin (co-founder of Danger), Rich Miner (co-founder of Wildfire Communications, Inc.) Nick Sears (once VP at T-Mobile) Chris White (headed design and interface development at WebTV)

y Android was bought by Google in 2005. Its co-founders went to work for Google y Google and other members of the Open Handset Alliance

collaborated on Android's development and release y Android has been available under a free software / open source license since October ,2008

Meet Android Co-Founders
y Rick Miner y

Andy Rubin

Nick Sears

Chris White picture not yet found

Operating System Overview
y Powered by the Linux kernel y Consists of 12 million lines of code including: 3 million lines of XML 2.8 million lines of C 2.1 million lines of Java 1.75 million lines of C++

Current API Distribution
y Version 1.0 was released on 23rd September 2008 y Newest version, 3.0, was release on 26th January

2011. y Distribution as of 01/04/11

Android Architecture
y 5 major components: Applications, Application Frameworks, Libraries,

Android Runtime, and Linux Kernel

Platform Architecture Videos
y Presenter: Mike Cleron, Android development team

member. y Video 1 of 3 (13 minute): architecture overview + replacing and reusing components example

Application Components
y An activity presents a visual user interface

Present a list of menu items users can choose Display photographs along with their captions Activities work together to form a cohesive user interface, however each activity is independent of the others. y Service doesn't have a visual user interface, runs in the background for an indefinite period of time Media player¶s music playback service

Application Components (Cont.)
y Broadcast receiver: is a component that receives and reacts to

broadcast announcements let other applications know that some data has been downloaded to the device and is available for use.
y Content provider :

Makes a specific set of the application's data available to other applications Enables other applications to retrieve and store data of the type it controls

Activity Life Cycle

Android Features Part 1
y Application framework enabling reuse and replacement of components y Dalvik virtual machine optimized for mobile devices y Integrated browser based on the open source WebKit engine y Optimized graphics powered by

Custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional)
y SQLite for structured data storage y

Android Features Part 2
y Media support for common audio, video, and still image formats

(MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF)

y GSM Telephony (hardware dependent) y Bluetooth, EDGE, 3G, and WiFi (hardware dependent) y Camera, GPS, compass, and accelerometer (hardware


y Rich development environment including a device emulator,

tools for debugging, memory and performance profiling, and a plugin for the Eclipse IDE


Application Fundamentals
y Written in the Java programming language. y Code along with any required data and resource files are compiled into an Android package, .apk file. y Installed on mobile devices y Runs in its own Linux process y Has its own virtual machine (VM), y Is assigned a unique Linux user ID Permissions are set so that the application's files are visible only to that user and only to the application itself y s.html

Android Central Feature
y Replace and Reuse

One application can make use of elements of other applications provided those applications permit it. One application doesn't incorporate the code of the other application or link to it. Rather, it simply starts up that piece of the other application when the need arises. y For this to work, the system must be able to start an application process when any part of it is needed, and instantiate the Java objects for that part. y Unlike applications on most other systems, Android applications don't have a single entry point for everything in the application (no main() function, for example). y Rather, they have essential components that the system can instantiate and run as needed.

y Is the 5th key class y Objects that hold the content of the message y Activities, services, and broadcast receivers ² are activated by


For activities and services, it names the action being requested and specifies the URI of the data to act on, among other things
Request for an activity to present an image to the user or let the user edit some text

For broadcast receivers, it names the action being announced
Announce to interested parties that the camera button has been pressed

Manifest file
y Before Android can start an application component, it must learn that the component exists. y Applications must declare their components in a manifest file y Is a structured XML file, named AndroidManifest.xml for all applications. y Declares the application's components y Names any libraries the application needs to be linked against (besides the default Android library) y Identifies any permissions the application expects to be granted

Manifest File Example
y y y y y y y y y y y y y y y y y

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="" package="com.example.helloandroidtoo" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true"> <activity android:name=".HelloAndroid" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> android:debuggable="true" </application> <uses-sdk android:minSdkVersion="8" /> </manifest>

Supported Operating Systems
Windows XP (32-bit), Vista (32- or 64-bit), or Windows 7 (32- or 64-bit) Mac OS X 10.5.8 or later (x86 only) Linux (tested on Ubuntu Linux, Lucid Lynx) 

GNU C Library (glibc) 2.7 or later is required. On Ubuntu Linux, version 8.04 or later is required. 64-bit distributions must be capable of running 32-bit applications

Supported Development Environments
y Recommended: Eclipse Eclipse IDE 3.4 (Ganymede) or greater 

Eclipse IDE for Java Developers Eclipse Classic (versions 3.5.1 and higher) Eclipse IDE for Java EE Developers

Eclipse JDT plug-in (included in most Eclipse IDE packages) JDK 5 or JDK 6 (JRE alone is not sufficient) Android Development Tools plug-in (recommended)

y Other development environments or IDEs JDK 5 or JDK 6 (JRE alone is not sufficient) Apache Ant 1.8 or later y Not compatible with Gnu Compiler for Java (gcj)

Set up Development Environment
y Review system requirements y Installing Java SDK y Download Eclipse IDE y Install Android SDK y Installing ADT plug-in for Eclipse y Adding Platforms and Components

Installing Java SDK
y Website: y y y y y y y y y y html Takes about 5 minutes Latest version: 1.6.23 Select the standard edition Select platform Check license agreement Select file in the ³Available Files´ Select ³Run´ to start installing Accept all default settings unless you want to customize. Don¶t need immediate registration Java SDK will be installed on C drive by default
For example: C:\Program Files\Java\jdk1.6.0_23

Java SDK Directory

Download Eclipse Takes about 3 Minutes Select package Select zip file for your OS Click on ³Download´ On ³File Download´ dialog, select ³Save´ to save the .zip file y After zip file is completely downloaded, unzip it. y Eclipse application is located under ³eclipse´ folder
y y y y y y
y For example: C:\Users\chau\Desktop\eclipse-SDK-3.6.1-


Eclipse Directory

Notes on Eclipse Tutorial
y Instructions written based on older version y Missing steps y HelloWorld tutorial: check on ³Create public static main «.´ y First time ³Run as Java application´ is not available y Other note: by default, Eclipse project is configured

to ³Build Automatically´ (Project->Build Automatically)

Install Android SDK
y Website: y Takes 10-15 minutes y Installer will verify if Java has been installed and stop installing if Java SDK is missing y Accept most defaults y Accept license agreement y Optionally, install additional packages when Android SDK and Android Virtual Device (AVD) Manager dialog open. Select ³Available Packages´ and select package (s) to install AndroidSDKInstallation.pptx

Install ADT Plugin For Eclipse
y Go to Android SDK Installing website for

instructions. y 2 main steps.
y Use Eclipse to download

Download ADT Plugin.pptx
y Configure

Configure ADT Plugin.pptx

Android Emulator
y Virtual mobile device that runs on computer. y Can be used to prototype, develop, and test Android applications

without using a physical device. y

Create Android Virtual Device (AVD)
y An Android Virtual Device (AVD) is a device configuration for the emulator that allows you to model real world devices. y In order to run an instance of the emulator, you must create an AVD. y On Eclipse, select Window -> Android SDK and AVD Manager y Click New to create a new AVD. y Fill in the details for the AVD. Give it a name, a platform target, an SD card size (512), and a skin (HVGA is default). y Click Create AVD. y Launch an emulator with the AVD by clicking Start

Hello Android Tutorial Step 1
Create New Android Project From Eclipse IDE: Select File -> New -> Project to open ³New File´ dialog On ³New File´ dialog: expand ³Android´ folder, then select ³Android Project´, then click on ³Next´ button

Create Project

Select Android Project

Hello Android Tutorial Step 2
Specify project properties Project name: HelloAndroid Build target: 2.2
Might need to create the target first (See Create AVD)

Application name: Hello, Android Package name: com.example.HelloAndroid Select ³Create Activity´ with ³HelloAndroid´ as name Min SDK Version: 8 Click on ³Finish´ button.

Hello Android Tutorial Step 3
Edit/Add code in the ³onCreate´ method
Comment out the following line //setContentView(R.layout.main); Add the following lines TextView tv = new TextView(this);

tv.setText("Hello, Android!!!\nWhat's up urban?"); setContentView(tv);
y Save the file , then Build the project if needed

*** Might need to import 2 new packages by clicking on the red cross on the left hand side of that line

Project Files

Project Files

Newly added code

Hello Android Tutorial Step 4
Run application using emulator Click ³Run As´ to open ³Run As´ dialog Might need to create an Android Virtual device. Select ³Android Application Click on ³OK´ 2 command prompts pop up and go away Emulator pop ups, then go through a few stages and displays. Wait for a few minutes for Activity Manager to complete launching the activity. Console displays message below.

³Activity Manager: Starting: Intent { act=an «.}´, click on ³Menu´ to see the ³Hello World Message´ Click on ³Menu´ button, ³Hello Android´ message will display. Click ³Home´ button on emulator Click on ³«´ on screen, ³Hello, Android´ application icon display on screen. Double click on app icon to display the app message

After Emulator ³locked´ screen appear.
y y y y

³Run As´ Dialog

Emulator Initializing

Console Messages

Emulator Startup Screen

Hello Android Running

Emulator Home

Applications Screen

Run On Device
y Must set up device, Android environment, and driver

first (see next slide) y Connect USB cable from phone to PC y Run
y Eclipse automatically install the application, .apk file,

and run it

Developing on a Device
y Declare your application as "debug-able" in your Android Manifest. y Turn on "USB Debugging" on your device. y Install USB driver y If using Android Developer Phone (ADP): Nexus One, or Nexus S, install Google Windows USB Driver y Otherwise, find a link to the appropriate OEM driver in the OEM USB Drivers document y Install HTC Sync Make sure generic/incomparable driver has been removed Take about 5 minutes Choose ³Complete´ Set up type. Install HTC Sync.pptx

Connect phone as ³Disk Drive´, not ³Charge Only´ or ³USB Tethering´ y

Install APK File via Android Market
y Copy the APK file to your Android¶s memory card

and insert the card into your phone. y Download and install the Apps Installer application from the Android Market y Once installed, run Apps Installer , browse to the APK file on the memory card. y Click and install your APK file.

Install APK File Using Android SDK
y Android Debug Bridge is a tool that allows manage

the state of an emulator instance or Androidpowered device y Install appropriate driver y Connect phone to PC via USB data cable y Run command line from SDK's platform-tools/ directory :
y adb -d install

C:\Users\chau\workspace\HelloFormStuffs\bin\Hell oFormStuffs.apk

Install APK File Result

Create Project From Existing Source
y For example: platform ApiDemos y Create a new project from existing source y Browse to and select ApiDemos folder y Select Build Target y Click on ³Finish´

Create ApiDemos Project

Android Phone Sensors
y Accelerometer Senses changes in orientation allowing the device to know when it is tilted on its side y Proximity sensor Deactivates the display and touch screen when the device is brought near the face during a call y Ambient light sensor Adjusts the display brightness which in turn saves battery power y E-compass Provides orientation with respect to Earth's magnetic field y Camera y GPS y Microphone

Sensing Related Packages
y Media y ia/package-summary.html y Location y tion/package-summary.html y Hardware y dware/Sensor.html

Sensor API Demo
y Package:; y Displays the values of the acceleration sensor graphically. y Get sensor manager mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); y Register listener for 4 sensor types mSensorManager.registerListener(mGraphView,

y Override onSensorChanged(«) to display the changed value



Hardware Package Summary

Android SDK Disk Storage

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.