Android Concepts and Programming TUTORIAL 1



Similar documents
Chapter 2 Getting Started

Android Development. Marc Mc Loughlin

Mobile Application Development

Android Development Tutorial. Human-Computer Interaction II (COMP 4020) Winter 2013

How to develop your own app

Now that we have the Android SDK, Eclipse and Phones all ready to go we can jump into actual Android development.

Android Sensors. CPRE 388 Fall 2015 Iowa State University

Using the Android Sensor API

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

Getting Started: Creating a Simple App

Arduino & Android. A How to on interfacing these two devices. Bryant Tram

Android For Java Developers. Marko Gargenta Marakana

Smartphone market share

4. The Android System

Introduction to Android Programming (CS5248 Fall 2015)

ELET4133: Embedded Systems. Topic 15 Sensors

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

Sensors & Motion Sensors in Android platform. Minh H Dang CS286 Spring 2013

Android Programming and Security

Frameworks & Android. Programmeertechnieken, Tim Cocx

Android Basics. Xin Yang

Android Sensor Programming. Weihong Yu

06 Team Project: Android Development Crash Course; Project Introduction

An Introduction to Android

Android Programming Basics

Android 多 核 心 嵌 入 式 多 媒 體 系 統 設 計 與 實 作

MMI 2: Mobile Human- Computer Interaction Android

Android Sensors. XI Jornadas SLCENT de Actualización Informática y Electrónica

CS 403X Mobile and Ubiquitous Computing Lecture 6: Maps, Sensors, Widget Catalog and Presentations Emmanuel Agu

Presenting Android Development in the CS Curriculum

Lab 1 (Reading Sensors & The Android API) Week 3

Developing NFC Applications on the Android Platform. The Definitive Resource

directory to "d:\myproject\android". Hereafter, I shall denote the android installed directory as

Basics. Bruce Crawford Global Solutions Manager

CS378 -Mobile Computing. Android Overview and Android Development Environment

Developing Android Applications: Case Study of Course Design

Developing an Android App. CSC207 Fall 2014

App Development for Smart Devices. Lec #2: Android Tools, Building Applications, and Activities

Introduction to Android. CSG250 Wireless Networks Fall, 2008

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

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Getting Started With Android

Develop a Hello World project in Android Studio Capture, process, store, and display an image. Other sensors on Android phones

TUTORIAL. BUILDING A SIMPLE MAPPING APPLICATION

Android App Development. Rameel Sethi

OpenCV on Android Platforms

Getting started with Android and App Engine

Tutorial #1. Android Application Development Advanced Hello World App

l What is Android? l Getting Started l The Emulator l Hello World l ADB l Text to Speech l Other APIs (camera, bitmap, etc)

App Development for Smart Devices. Lec #5: Android Sensors

Android Application Development: Hands- On. Dr. Jogesh K. Muppala

Mocean Android SDK Developer Guide

How To Develop Android On Your Computer Or Tablet Or Phone

Mobile Application Development 2014

Università Degli Studi di Parma. Distributed Systems Group. Android Development. Lecture 2 Android Platform. Marco Picone

TUTORIALS AND QUIZ ANDROID APPLICATION SANDEEP REDDY PAKKER. B. Tech in Aurora's Engineering College, 2013 A REPORT

Introduction to Android Development. Jeff Avery CS349, Mar 2013

Introduction to Android

WEARIT DEVELOPER DOCUMENTATION 0.2 preliminary release July 20 th, 2013

With a single download, the ADT Bundle includes everything you need to begin developing apps:

Building Your First App

Android Application Development. Yevheniy Dzezhyts

Android Java Live and In Action

Android Introduction. Hello Mihail L. Sichitiu 1

Android Tutorial. Larry Walters OOSE Fall 2011

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

Developing Android Applications Introduction to Software Engineering Fall Updated 7 October 2015

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

Running a Program on an AVD

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

How to Create an Android Application using Eclipse on Windows 7

ANDROID. Programming basics

Developing Android Apps: Part 1

Lecture 1 Introduction to Android

Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department. Mobile Computing ECOM Eng. Wafaa Audah.

Android Apps Development Boot Camp. Ming Chow Lecturer, Tufts University DAC 2011 Monday, June 6, 2011

Admin. Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources. Recap: TinyOS. Recap: J2ME Framework

The "Eclipse Classic" version is recommended. Otherwise, a Java or RCP version of Eclipse is recommended.

Sensors and Cellphones

Location-Based Services Design and Implementation Using Android Platforms

MOVEIRO BT-200 Technical Information for Application Developer

Objective. Android Sensors. Sensor Manager Sensor Types Examples. Page 2

Jordan Jozwiak November 13, 2011

Android Environment SDK

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

Android Programming: Installation, Setup, and Getting Started

Introduction to NaviGenie SDK Client API for Android

Transcription:

Android Concepts and Programming TUTORIAL 1 Kartik Sankaran kar.kbc@gmail.com CS4222 Wireless and Sensor Networks [2 nd Semester 2013-14] 20 th January 2014

Agenda PART 1: Introduction to Android - Simple Android Apps: HelloWorldApp and ButtonApp PART 2: Introduction to Sensors - Simple Sensor App: AngleApp Goal of the Tutorials: - Help you quickly get started with Android programming. - Cover concepts not explained well on the Android website. 2

Introduction to Android What is Android? - Linux-based Operating System for mobile devices - Developed by Android, Inc. (later purchased by Google) - First Android phone in October 2008 - Multiple companies producing Android phones: Samsung, HTC, LG, Motorola, ASUS, and many others 3

Introduction to Android Android is not just Linux ported to mobile phones - Linux code: < 500 MB - Android code: > 10 GB Why Linux? - Process management - Security - Code can be forked 4

Introduction to Android Android Version History: (most phones run Jelly Bean) 5

Introduction to Android Typical specs: - 1 GB RAM, 16 GB flash storage, 1 GHz multi-core processor, GPU - Have variety of sensors! - Limited battery : approx 2000 mah Mobiles have limited memory (not anymore!): - Android can kill an App taking too much memory - Each App has an upper limit on heap space: 32 MB on Galaxy Nexus Major battery drainers: - Display, Processor, 3G, GPS 6

Introduction to Android How does Android manage Applications? - Multiple applications can run at same time - Only one instance of an App runs at a time - Typical buttons: Home, Back, Menu, Search Home button: Similar to minimizing a window (state retained) Back button: Similar to closing a window (state destroyed) - After App destroyed, its still in memory! 7

How to write Applications? Introduction to Android - Apps are mostly written in Java. - Compiled to Dalvik (dex) code. (Dalvik is a village in Iceland) Each App runs: - On Dalvik VM - Separate process - Separate User ID (for security) Why Dalvik? - Memory Optimized (Jar 113 KB Dex 20 KB) - Avoid paying money to Sun (Oracle) Why not directly convert Java Dex? - Use 3 rd party Java libraries (Image from Marakana s slides on Android Internals) 8

Installation Steps: 1. Install Java (Version 6 or above) 2. Install Android SDK Your first Android program - http://developer.android.com/sdk/index.html If any problem, then email/meet me 9

Your first Android program Installation Steps: 3. Install Android APIs (needs a good internet connection, takes a while) - http://developer.android.com/sdk/installing/adding-packages.html - SDK Manager.exe (at root of SDK installation folder) - API 17 + SDK tools + SDK platform tools are needed 10

Your first Android program Installation Steps: 4. Install an IDE of your choice a. Eclipse - ADT Bundle has Android SDK + Eclipse IDE + ADT Plugin http://developer.android.com/sdk/index.html - If you already have Eclipse (>= 3.6.2 Helios), install the ADT plugin: http://developer.android.com/sdk/installing/installing-adt.html 11

Installation Steps: 4. Install an IDE of your choice b. IntelliJ (approx 120 MB) Your first Android program - http://www.jetbrains.com/idea/download/index.html c. Emacs (or any text editor of your choice) 12

Your first Android program Installation Steps: 5. Install phone s device drivers (Mac users skip this step) a. Windows - http://developer.android.com/tools/extras/oem-usb.html - http://www.samsung.com/us/support/owners/product/sch-i515msavzw b. Linux (/etc/udev/rules.d/51-android.rules) - http://developer.android.com/tools/device.html - SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", MODE="0666", GROUP="plugdev" 13

Creating an Android project: Your first Android program 1. Using command line $ android list targets (to get target IDs) $ android create project --target 9 --name HelloWorld --path./helloworld --activity HelloWorldActivity --package nus.cs4222.helloworld 2. Using an IDE - File New Project - Fill in the details, similar to above 14

Project Structure: Your first Android program src: Your source code res/layout/main.xml: Your GUI libs: Library jars In Android, the GUI screen is called an Activity (will be covered in detail in next tutorial) 15

Your first Android program res/layout/main.xml : (already created by default) <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <TextView android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="hello World!" /> </LinearLayout> 16

Your first Android program HelloWorldActivity.java : (already created by default) public class HelloWorldActivity extends Activity { /** Called when the activity is first created. */ @Override public void oncreate( Bundle savedinstancestate ) { super.oncreate( savedinstancestate ); } } // Specify what GUI to use (res/layout/main.xml) // R stands for Resources setcontentview( R.layout.main ); 17

Turn on USB debugging on the phone: Settings Developer Options Enable USB Debugging Make sure you installed the USB Driver for this phone! (in this case, Samsung Galaxy Nexus) 18

Build (compile) your App: 1. Using command line: $ ant debug 2. Using an IDE: Build button/menu - App: bin/helloworld-debug.apk Install App on phone: 1. Using command line: $ adb install -r bin/helloworld-debug.apk 2. Using an IDE: Install/Run button/menu 19

Debugging (use the filter field most of the time): Monitor.bat (AKA ddms.bat) 20

Your first Android program Adding more GUI widgets : - EditText: User can enter text here - Button: Pressing it triggers an action - TextView: Displays some text 1. Enter text here 2. Press the button 3. Text gets appended here 21

res/layout/main.xml : (add Button and EditText widgets) <LinearLayout...> <EditText android:id="@+id/edittext_message" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="" /> <Button android:id="@+id/button_send" <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="send Message" /> android:id="@+id/textview_message"... /> </LinearLayout> Your first Android program Widgets have IDs @ Referring to a resource + Adds this ID to the R class GUI layout defined using XML 22

HelloWorldActivity.java : Your first Android program public class HelloWorldActivity extends Activity { /** Called when the activity is first created. */ public void oncreate( Bundle savedinstancestate ) {... } } // Text View (displays messages) private TextView textview_message; // Edit Text (user enters message here) private EditText edittext_message; // Button to trigger an action private Button button_send; GUI widgets in Java code 23

Your first Android program HelloWorldActivity.java : public class HelloWorldActivity extends Activity { /** Called when the activity is first created. */ public void oncreate( Bundle savedinstancestate ) {... // Get references to the GUI widgets textview_message = (TextView) findviewbyid( R.id.TextView_Message ); edittext_message = (EditText) findviewbyid( R.id.EditText_Message ); button_send = (Button) findviewbyid( R.id.Button_Send ); } } 24

HelloWorldActivity.java : Your first Android program public void oncreate( Bundle savedinstancestate ) {... // Set the button's click listener button_send.setonclicklistener( new View.OnClickListener() { public void onclick( View v ) { // Change the text view String newtext = textview_message.gettext() + "\n New Message: " + edittext_message.gettext(); textview_message.settext ( newtext ); } } ); } 25

Your first Android program Android online tutorials: http://developer.android.com/guide/components/fundamentals.html http://developer.android.com/training/basics/firstapp/index.html Note: Many Android programmers directly jump into coding. However, it is more important to understand the concepts first before writing complex Apps. Otherwise, coding becomes a messy headache. 26

Break

Introduction to Sensors 1. What sensors are available? What do they sense? 2. How to access sensor data in Android? 3. What are the sensor properties and characteristics? 4. Why is it important to understand each sensor s properties? 5. Simple Sensor App: AngleApp 28

Sensors What do they sense? 1. Motion Sensors - Accelerometer (also: Gravity, Linear Accl) - Gyroscope - Rotation Vector 2. Position Sensors - Magnetic Field - Orientation - Proximity 3. Environmental Sensors - Temperature, Light, Pressure, Humidity 4. Others - GPS, Camera, Microphone, Network May be physical or virtual http://www.youtube.com/watch?v=c7jq7rpwn2k Understanding the physics behind the sensors These sensors have different APIs 29

Sensors How to access them in code? SensorManager manager = (SensorManager) getsystemservice( Context.SENSOR_SERVICE ); Sensor light = manager.getdefaultsensor( Sensor.TYPE_LIGHT ); protected void onresume() { } manager.registerlistener( this, light, protected void onpause() { } manager.unregisterlistener( this ); SensorManager.SENSOR_DELAY_NORMAL); public void onsensorchanged( SensorEvent event ) { } float lux = event.values[0]; Why float and not double? Returns null if sensor not present Sampling Rate Listener for sensor changes 30

Sensors How to access them in code? LocationManager manager = (LocationManager) getsystemservice( Context.LOCATION_SERVICE ); List <String> providers = manager.getproviders( true ); manager.requestlocationupdates( gps, TIME_PERIOD, MIN_DISTANCE_MOVED, this ); Sampling Rate (0 for max frequency) Returns subset of { gps, network, passive } manager.removeupdates( this ); public void onlocationchanged( Location location ) { double latitude = location.getlatitude(); } Listener for location changes 31

Sensors Note about Location APIs Two APIs: - Old API: LocationManager (Raw GPS) - New API: LocationClient (Filtered location value fused with sensors) For PA1, use the old API. For Project work, use the new API. 32

Sensors What rate to sample? - Depends on event frequency (Eg: Walking, Occupancy) - Power consideration (Eg: Accl 20 Hz v/s 1 Hz) Android gotchas: - Android delivers data at faster rate than specified - Actual sampling rate can vary with time ( onsensorchanged() ) 33

Sensors Properties, Characteristics, Errors 1. Accuracy and Precision 2. Noise (Eg: Accl) 3. Drift (Eg: Gyro) 34

Sensors Importance of understanding them Example Integrating Accelerometer (m/sec 2 ) Velocity v/s Very Noisy Integrating Gyroscope (radian/sec) Angle rotated Less noisy, but drifts with time Combine Accl + Gyro: Sensor Fusion Q: Can Accl be used to get distance? 35

Sensors Developing a good Sensor App Example: Developing a Walking Fitness app What sensors to use Data Collection at required sampling rate Understand sensor characteristics Filtering, Signal Analysis, Machine Learning, Calibration 36

Sensors AngleApp App that displays angle of the phone with the horizontal plane - Calculates the angle between the gravity vector [0, 0, g] and phone s positive y-axis 37

Sensors Different Co-ordinate axes 1. Phone co-ordinate axes (smartphone + tablet) used by sensors 2. World co-ordinate axes 3. Screen (virtual world) co-ordinate axes remapcoordinatesystem() getrotationmatrix() 38

Questions?

Thank You!