Using Sensors on the Android Platform. Andreas Terzis Android N00b



Similar documents
Android Sensor Programming. Weihong Yu

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

Android Sensors. CPRE 388 Fall 2015 Iowa State University

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

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

Developing Sensor Applications on Intel Atom Processor-Based Android* Phones and Tablets

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

Using the Android Sensor API

Android app development course

Android Framework. How to use and extend it

ELET4133: Embedded Systems. Topic 15 Sensors

Obsoleted chapter from The Busy Coder's Guide to Advanced Android Development

Programming Mobile Applications with Android

E0-245: ASP. Lecture 16+17: Physical Sensors. Dipanjan Gope

06 Team Project: Android Development Crash Course; Project Introduction

Using Extensions or Cordova Plugins in your RhoMobile Application Darryn

! Sensors in Android devices. ! Motion sensors. ! Accelerometer. ! Gyroscope. ! Supports various sensor related tasks

Android Programming Lecture 18: Menus Sensors 11/11/2011

Android. Mobile Computing Design and Implementation. Application Components, Sensors. Peter Börjesson

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

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

Android Services. Android. Victor Matos

Designing An Android Sensor Subsystem Pitfalls and Considerations

Android Concepts and Programming TUTORIAL 1

Android Services. Services

Internal Services. CSE 5236: Mobile Application Development Instructor: Adam C. Champion Course Coordinator: Dr. Rajiv Ramnath

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

Module 1: Sensor Data Acquisition and Processing in Android

CSE476 Mobile Application Development. Yard. Doç. Dr. Tacha Serif Department of Computer Engineering Yeditepe University

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

WEARIT DEVELOPER DOCUMENTATION 0.2 preliminary release July 20 th, 2013

Performance issues in writing Android Apps

Android app development course

Developing Android Apps for BlackBerry 10. JAM854 Mike Zhou- Developer Evangelist, APAC Nov 30, 2012

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

Pedometer Project 1 Mr. Michaud /

HP TouchPad Sensor Setup for Android

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

An Android-based Instant Message Application

Introduction to NaviGenie SDK Client API for Android

Sensor Fusion Mobile Platform Challenges and Future Directions Jim Steele VP of Engineering, Sensor Platforms, Inc.

Introducing Mobile Application Development for Android. Presented by: Ahmed Misbah

Lecture 1 Introduction to Android

Android Introduction. Hello Mihail L. Sichitiu 1

SENSORS ON ANDROID PHONES. Indian Institute of Technology Kanpur Commonwealth of Learning Vancouver

Kathy Au Billy Yi Fan Zhou Department of Electrical and Computer Engineering University of Toronto { kathy.au, billy.zhou }@utoronto.

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

AdFalcon Android SDK Developer's Guide. AdFalcon Mobile Ad Network Product of Noqoush Mobile Media Group

AUTOMATIC HUMAN FREE FALL DETECTION USING ANDROID

How to develop your own app

ELDERLY SUPPORT - ANDROID APPLICATION FOR FALL DETECTION AND TRACKING TEJITHA RUDRARAJU. B.E, Anna University, India, 2011 A REPORT

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

Android Basics. Xin Yang

Android Sensors This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. CC-BY Google

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

Tutorial #1. Android Application Development Advanced Hello World App

How to Convert 3-Axis Directions and Swap X-Y Axis of Accelerometer Data within Android Driver by: Gang Chen Field Applications Engineer

An intelligent Smartphone application

Android Persistency: Files

MMI 2: Mobile Human- Computer Interaction Android

Using the Adafruit Unified Sensor Driver. Created by Kevin Townsend

Evading Android Emulator

Android For Java Developers. Marko Gargenta Marakana

Frameworks & Android. Programmeertechnieken, Tim Cocx

How to build your first Android Application in Windows

Mono for Android Activity Lifecycle Activity Lifecycle Concepts and Overview

Developing Android Apps for BlackBerry 10. JAM 354 Matthew Whiteman - Product Manager February 6, 2013

Computer Graphics on Mobile Devices VL SS ECTS

CSE476 Mobile Application Development. Yard. Doç. Dr. Tacha Serif Department of Computer Engineering Yeditepe University

Programming with Android: Localization and Google Map Services. Dipartimento di Scienze dell Informazione Università di Bologna

Sensors and Cellphones

Chapter 2 Getting Started

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

4. The Android System

Developing an Android App. CSC207 Fall 2014

IOIO for Android Beginners Guide Introduction

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

Transcription:

Using Sensors on the Android Platform Andreas Terzis Android N00b

Hardware-oriented Features Feature Camera Sensor SensorManager SensorEventListener SensorEvent GeoMagneticField Description A class that enables your application to interact with the camera to snap a photo, acquire images for a preview screen, and modify parameters used to govern how the camera operates. Class representing a sensor. Use getsensorlist(int) to get the list of available Sensors. A class that permits access to the sensors available within the Android platform. An interface used for receiving notifications from the SensorManager when sensor values have changed. An application implements this interface to monitor one or more sensors available in the hardware. This class represents a sensor event and holds information such as the sensor type (e.g., accelerometer, orientation, etc.), the time-stamp, accuracy and of course the sensor's data. This class is used to estimated estimate magnetic field at a given point on Earth, and in particular, to compute the magnetic declination from true north.

SensorManager Class SensorManager lets you access the device's sensors Get an instance of this class by calling Context.getSystemService() with the argument SENSOR_SERVICE Methods (partial list) List<Sensor> getsensorlist(int type) Static float[] getorientation(float []R,float []values) registerlistener(sensoreventlistener listener, Sensor sensor, int rate) Rate is only a hint to the system: Fastest, game, normal, user interface

Sensor Class Class representing a sensor Sensor type Accelerometer, gravity, gyroscope, pressure, light, magnetic field, proximity, temperature, etc. Methods (partial list) public string getname() public float getpower() public float getmaximumrange()

SensorEvent Class This class represents a Sensor event and holds information such as the sensor's type, the time-stamp, accuracy and of course the sensor's data. Fields: public int accuracy public Sensor sensor public long timestamp public final float[] values

SensorEventListener Interface To interact with a sensor, an application must register to listen for activity related to one or more sensors. Registering takes place with the registerlistener method of the SensorManager class. Two required methods onsensorchanged(sensorevent event): method is invoked whenever a sensor value has changed onaccuracychanged(sensor sensor, int accuracy): method is invoked when the accuracy of a sensor has been changed

Registering to receive sensor events public class SensorReader extends Activity implements SensorEventListener { SensorManager sm = null; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // get reference to SensorManager sm = (SensorManager) getsystemservice(sensor_service); protected void onresume() { super.onresume(); // register as a listener for the accel. sensors sm.registerlistener(this, Sensor.TYPE_ACCELEROMETER, SensorManager.SENSOR_DELAY_NORMAL); protected void onstop() { // unregister listener sm.unregisterlistener(this); super.onstop();

Receiving events public void onsensorchanged(sensorevent event) { synchronized (this) { if (event.sensor == Sensor.SENSOR_ACCELEROMETER) { xviewa.settext("accel X: " + event.values[0]); yviewa.settext("accel Y: " + event.values[1]); zviewa.settext("accel Z: " + event.values[2]); public void onaccuracychanged(sensor sensor, int accuracy) { Log.d(tag,"onAccuracyChanged: " + sensor.getname() + ", accuracy: " + accuracy);

Fall Detection Application Use a combination of acceleration and orientation sensor to detect people falling

Fall Detection Algorithm :Total acceleration of phone body The acceleration of absolute vertical direction 1. For total acceleration: If (diff between within a time window ) > Check the difference between the max and min following in next time window If this difference is larger than some threshold, a fall is potentially detected 2. For absolute vertical direction: The same algorithm as 1, but different threshold values - If 1 and 2 say yes, algorithm reports a fall Dai et. al., PerFallD: A Pervasive Fall Detection System Using Mobile Phones

Code Walkthrough

Example: GPS (I) Add LocationManager to get Updates public class GPSSimulator extends Activity { private LocationManager lm; private LocationListener locationlistener; // Called when the activity is first created. @Override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); // use the LocationManager class to obtain GPS locations lm = (LocationManager) getsystemservice(context.location_service); locationlistener = new MyLocationListener(); lm.requestlocationupdates( LocationManager.GPS_PROVIDER, 0, 0, locationlistener);

Example GPS (II): Add MyLocationListener private class MyLocationListener implements LocationListener { @Override public void onlocationchanged(location loc) { if (loc!= null) { Toast.makeText(getBaseContext(), "Location changed : Lat: " + loc.getlatitude() + " Lng: " + loc.getlongitude(), Toast.LENGTH_SHORT).show(); @Override public void onproviderdisabled(string provider) { // TODO Auto-generated method stub @Override public void onproviderenabled(string provider) { // TODO Auto-generated method stub @Override public void onstatuschanged(string provider, int status, Bundle extras) { // TODO Auto-generated method stub