Sensing. Possible sensors on devices – Documented in SensorEvent class Accelerometer (m/s 2 ) – acceleration in x, y, z axes Magnetic Field (micro Tesla)

Slides:



Advertisements
Similar presentations
Android Application Development Tutorial. Topics Lecture 4 Overview Overview of Sensors Programming Tutorial 1: Tracking location with GPS and Google.
Advertisements

Programming with Android: System Services Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Manifest File, Intents, and Multiple Activities. Manifest File.
Sensors.  Hardware devices that take measurements of the physical environment  Some examples  3-axis Accelerometer  3-axis Magnetic field sensor 
Cosc 5/4730 Input Keyboard, touch, and Accelerometer.
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
Real-Time Sensing on Android Reliable Mobile Systems Group Fiji Systems Inc. Yin Yan, Shaun Cosgrove, Ethan Blanton, Steven Y. Ko, Lukasz Ziarek
SMS. Short Message Service – Primarily text messages between mobile phones – First one sent December 3, 1982 “Merry Christmas” – In 2008 Approximately.
Introduction to Smartphone Sensors
Android sensors.
The Accelerometer and Gyroscope
CS378 - Mobile Computing Sensing and Sensors. Sensors "I should have paid more attention in Physics 41" Most devices have built in sensors to measure.
CS378 - Mobile Computing Sensing and Sensors. Sensors "I should have paid more attention in Physics 41" Most devices have built in sensors to measure.
Android Sensors & Async Callbacks Jules White Bradley Dept. of Electrical and Computer Engineering Virginia Tech
Introduction to Mobile Sensing with Smartphones Uichin Lee April 22, 2013.
Win8 on Intel Programming Course Modern UI : Sensors Cédric Andreolli Intel Software.
Multiple Choice Solutions True/False a c b e d   T F.
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
Getting Started with Android APIs Ivan Wong. Motivation - “Datasheet” - Recently exposed to what’s available in Android - So let’s see what API’s are.
Cosc 5/4730 Input Keyboard, touch, and Accelerometer.
Mobile Application Development Selected Topics – CPIT 490
Lecture # 9 Hardware Sensor. Topics 2  SensorManger & Sensor  SensorEvent & SensorEventListener  Example Application.
Mobile Programming Lecture 9 Bound Service, Location, Sensors, IntentFilter.
1 Localization and Sensing Nilanjan Banerjee Mobile Systems Programming (Acknowledgement: Jules White) University of Arkansas Fayetteville, AR
Doodlz App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
1 CMSC 628: Introduction to Mobile Computing Nilanjan Banerjee Introduction to Mobile Computing University of Maryland Baltimore County
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
23/10/2015 E.R.Edwards 23/10/2015 Staffordshire University School of Computing Introduction to Android Sensors.
Sensors – Part I SE 395/595.
로봇을 조종하자 3/4 UNIT 17 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 스마트 폰의 센서를 사용할 수 있다. 2.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
CS378 - Mobile Computing Sensing and Sensors Part 2.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Location. GPS Global Positioning System – At least 4 satellites typically used 3 required extra for error detection and altitude typically accurate within.
Mobile Device Development Camera and Sensors Dr.YingLiang Ma.
Module 8: Delegates and Events. Overview Delegates Multicast Delegates Events When to Use Delegates, Events, and Interfaces.
Sensors in android. App being more applicable Keeping track of your heart beat while jogging. Pointing the phone camera towards the night sky to know.
Sensors Nasrullah Khan Niazi. Using Device Sensors The Android SDK provides access to raw data from sensors on the device.The sensors,and their precision.
CS378 - Mobile Computing Sensing and Sensors Part 2.
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors Date: Feb 11, 2016.
Level 3 Tracking Tutorial R. Beuselinck 7 February 2001 Current status of level 3 tracking interface User access methods and parameter definitions Simple.
CPE 490/590 – Smartphone Development
CHAPTER 8 Sensors and Camera. Chapter objectives: Understand Motion Sensors, Environmental Sensors and Positional Sensors Learn how to acquire measurement.
User Interaction Radan Ganchev Astea Solutions. Content Basic input events Gestures Drag and drop Sensors.
CS371m - Mobile Computing Sensing and Sensors.
The Doodlz app enables you to paint by dragging one or more fingers across the screen. The app provides options for setting the drawing color.
Android Android Sensors Android Sensors: – Accelerometer – Gravity sensor – Linear Acceleration sensor – Magnetic Field sensor – Orientation.
Sensors in Android.
Vijay Kumar Kolagani Dr. Yingcai Xiao
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors.
Walk n’ Play Group #8 - Team Murali Krishna Goli Viswanath Patimalla
What's Happening Today Working with Images
Sensors, maps and fragments:
Vijay Kumar Kolagani Dr. Yingcai Xiao
Location Service and Sensors
CS499 – Mobile Application Development
Mobile Handset Sensors
CS371m - Mobile Computing Sensing and Sensors.
CIS 470 Mobile App Development
Interfaces.
Vijay Kumar Kolagani Dr. Yingcai Xiao
Android Topics Sensors Accelerometer and the Coordinate System
Android Programming Tutorial
CIS 493/EEC 492 Android Sensor Programming
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors.
Mobile Programming Sensors in Android.
Preference Activity class
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Sensing

Possible sensors on devices – Documented in SensorEvent class Accelerometer (m/s 2 ) – acceleration in x, y, z axes Magnetic Field (micro Tesla) – ambient magnetic field in x, y, z axes Light (lux) – ambient light level Proximity (cm) Temperature (degrees C) Other

Components of Sensing in Android SensorManager class Sensor class – Additional class (relative to Location) to handle multiple Sensor types – Metadata stored here (name, type, etc.) SensorEvent class – Sensor data stored here SensorEventListener interface – SensorListener interface has been deprecated

SensorManager class

SensorManager Concrete class Gives access to Sensor devices and classes Not instantiated directly – instantiated through the given context’s getSystemService() method Sensor Manager sm = (SensorManager)getSystemService(Context.SENSOR_SERVICE);

SensorManager important methods – getSensorList argument: integer indicating desired sensor type (or all sensors) returns List of all sensors of argument type – getDefaultSensor argument: integer indicating desired sensor type returns device’s sensor of argument type – registerListener arguments: context, sensor, and delay rate – unregisterListener arguments: SensorEventListener and optionally a Sensor

SensorManager Some fields in SensorManager class – Valid delay rates when registering a listener SENSOR_DELAY_X – X: FASTEST, GAME, NORMAL, UI – UI is most standard – good for typical development use – Other constants MAGNETIC_FIELD_EARTH_MAX (or MIN) GRAVITY_X – X: EARTH, MARS, NEPTUNE, etc. – GRAVITY_DEATH_STAR_I (first Star Wars Death Star) » x 10 –7 (of course, this is just an estimate…) Other (LIGHT_X, PRESSURE_STANDARD_ATMOSPHERE, etc.)

Sample code Instantiation SensorManager sm = (SensorManager)getSystemService(Context.SENSOR_SERVICE); Retrieve sensors List ls = sm.getSensorList(Sensor.TYPE_ALL); Retrieve specific sensor Sensor myAccelerometer = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); Registering a listener sm.registerListener(this, sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_UI); Unregistering a listener sm.unregisterListener(this, sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));

Sensor class

Concrete class Represents specific sensor Contains: – methods to obtain general metadata information – fields for specific sensor types

Sensor class important methods – getters for data getName() – returns String value (on Emulator: “Goldfish 3-axis Accelerometer”) getType() – returns int value (1 for Accelerometer) others important fields (all integers) – TYPE_ALL – TYPE_ZZZ (ZZZ is sensor type) ACCELEROMETER, LIGHT, TEMPERATURE, etc.

SensorEvent class

Concrete class Represents an event tied to a specific sensor Contains: – identification of the sensor causing the event – data associated with the event

SensorEvent class no methods (other than Object’s methods) important fields (all public) – sensor, accuracy, and timestamp – values – documented in SensorEvent class float array containing values associated with the sensed information – if sensor is accelerometer » 3 element array with x, y, z axes’ data – if sensor is temperature » 1 element array containing temperature – etc.

SensorEventListener interface

SensorEventListener Interface Notified by SensorManager if status changes SensorManager must register with the SensorEventListener for all desired Sensors

SensorEventListener 2 abstract methods – onAccuracyChanged sensors can have one of four levels of accuracy placement or calibration may affect accuracy parameters are the sensor (Sensor) and the accuracy (int) – onSensorChanged called whenever the value(s) of a Sensor have changed 1 parameter – the SensorEvent

Sample Code – onSensorChanged() public void onSensorChanged(SensorEvent event) { switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: ((TextView)findViewById(R.id.tvAccX)).setText("Acc X: " + event.values[0]); ((TextView)findViewById(R.id.tvAccY)).setText("Acc Y: " + event.values[1]); ((TextView)findViewById(R.id.tvAccZ)).setText("Acc Z: " + event.values[2]); break; case Sensor.TYPE_AMBIENT_TEMPERATURE: ((TextView)findViewById(R.id.tvTemp)).setText("Temp: " + event.values[0]); break;...cases continue for all desired sensors... }

SensorEventListener Registering/Unregistering a Manager with a Listener – methods in SensorManager class – take care to utilize resources effectively register in onResume() unregister in onPause()