Sensors in Android.

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

Mobile Handset Sensors. Outline Overview GPS Other Sensors 2.
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.
Introduction to Smartphone Sensors
Android sensors.
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.
Phone guide. Sensor Thermometer thermometer for measuring ambient temperature. However, there's a thermometer in pretty much any smartphone, and some.
Phone guide for people over 65. Not Smart Phones.
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
Android Sensors & Async Callbacks Jules White Bradley Dept. of Electrical and Computer Engineering Virginia Tech
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.
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
Sensing. Possible sensors on devices – Documented in SensorEvent class Accelerometer (m/s 2 ) – acceleration in x, y, z axes Magnetic Field (micro Tesla)
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
Doodlz App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Cosc 5/4730 Broadcast Receiver. Broadcast receiver A broadcast receiver (short receiver) – is an Android component which allows you to register for system.
1 CMSC 628: Introduction to Mobile Computing Nilanjan Banerjee Introduction to Mobile Computing University of Maryland Baltimore County
Sensors – Part I SE 395/595.
로봇을 조종하자 3/4 UNIT 17 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 스마트 폰의 센서를 사용할 수 있다. 2.
CS378 - Mobile Computing Sensing and Sensors Part 2.
Mobile Device Development Camera and Sensors Dr.YingLiang Ma.
Ambient Light Sensor The ambient light sensor is something that can detect the brightness of the phone screen. This is helpful for if your eyes are hurting.
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.
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
Sensors For Mobile Phones  Ambient Light Sensor  Proximity Sensor  GPS Receiver Sensor  Gyroscope Sensor  Barometer Sensor  Accelerometer Sensor.
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
CS378 - Mobile Computing Sensing and Sensors Part 2.
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors Date: Feb 11, 2016.
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
CPE 490/590 – Smartphone Development
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
CHAPTER 8 Sensors and Camera. Chapter objectives: Understand Motion Sensors, Environmental Sensors and Positional Sensors Learn how to acquire measurement.
Mobile Software Development for Android - I397 IT COLLEGE, ANDRES KÄVER, WEB:
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.
Smartphone sensors Gyroscope: The gyroscope is a sensor that can provide orientation information with great precision. Magnetometer: It is able to detect.
Mobile phone sensors. Sensors Sensors gyroscope The gyroscope is a sensor that can provide orientation information as well. This sensor can tell how.
Vijay Kumar Kolagani Dr. Yingcai Xiao
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
Mobile Software Development for Android - I397
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors.
Goal : Develop a software that converts arm movements into messages
Vijay Kumar Kolagani Dr. Yingcai Xiao
CS499 – Mobile Application Development
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
Mobile Handset Sensors
CS371m - Mobile Computing Sensing and Sensors.
CIS 470 Mobile App Development
Vijay Kumar Kolagani Dr. Yingcai Xiao
CIS 470 Mobile App Development
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.
CIS 493/EEC 492 Android Sensor Programming
CIS 493/EEC 492 Android Sensor Programming
Mobile Programming Sensors in Android.
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Sensors in Android

Types of Sensors Motion Sensor Environmental Sensors Position sensors Accelerometers Gravity sensors Gyroscopes Rotational vector sensors Environmental Sensors Barometers Photometers Thermometers Position sensors Orientation sensors Magnetometers

Sensors in Android Sensor Type Description Common Uses TYPE_ ACCELEROMETER Hardware Measures the acceleration force in m/s2 that is applied to a device on all three physical axes (x, y, and z), including the force of gravity. Motion detection (shake, tilt, etc.). AMBIENT_TEMPERATURE Measures the ambient room temperature in degrees Celsius (°C). Monitoring air temperatures. GRAVITY Software or Hardware Measures the force of gravity in m/s2 that is applied to a device on all three physical axes (x, y, z). GYROSCOPE Measures a device's rate of rotation in rad/s around each of the three physical axes (x, y, and z). Rotation detection (spin, turn, etc.). LIGHT Measures the ambient light level (illumination) in lx. Controlling screen brightness. LINEAR_ACCELERATION Measures the acceleration force in m/s2 that is applied to a device on all three physical axes (x, y, and z), excluding the force of gravity. Monitoring acceleration along a single axis. MAGNETIC_FIELD Measures the ambient geomagnetic field for all three physical axes (x, y, z) in μT. Creating a compass.

Sensors in Android TYPE_ ORIENTATION Software Measures degrees of rotation that a device makes around all three physical axes (x, y, z). As of API level 3 you can obtain the inclination matrix and rotation matrix for a device by using the gravity sensor and the geomagnetic field sensor in conjunction with the getRotationMatrix() method. Determining device position. PRESSURE Hardware Measures the ambient air pressure in hPa or mbar. Monitoring air pressure changes. PROXIMITY Measures the proximity of an object in cm relative to the view screen of a device. This sensor is typically used to determine whether a handset is being held up to a person's ear. Phone position during a call. RELATIVE_HUMIDITY Measures the relative ambient humidity in percent (%). Monitoring dewpoint, absolute, and relative humidity. ROTATION_VECTOR Software or Hardware Measures the orientation of a device by providing the three elements of the device's rotation vector. Motion detection and rotation detection. TEMPERATURE Measures the temperature of the device in degrees Celsius (°C). This sensor implementation varies across devices and this sensor was replaced with the TYPE_AMBIENT_TEMPERATURE sensor in API Level 14

Android Sensor Framework Determining what sensors are available Determining the sensor’s capability Defining min sampling rate Acquiring raw sensor data Registering sensor event listeners

Sensor Framework SensorManager Sensor SensorEvent SensorEventListener Accessing/listing sensors Registering/unregistering sensor event listeners Acquiring orientation information Sensor Determining the capability of sensors SensorEvent Providing information about sensor events Including raw sensor data, sensor, the accuracy, and timestamp. SensorEventListener Containing callbacks to receiving notifications of sensor events

Identifying Sensors Get a SensorManager SensorManager mSM = (SensorManager)getSystemService(Context.SENSOR_SERVICE); Get a list of all sensors available on device List<Sensor> sensors = mSM.getSensorList(Sensor.TYPE_ALL); Get a list of all sensors of a given type List<Sensor> sensors = mSM.getSensorList(Sensor.TYPE_GRAVITY); Get the default sensor of a given type Multiple sensors of the same type One must be assigned as default If (mSM.getDefaultSensor(Sensor.TYPE_GRAVITY) != null) { // sensor available } else { // no gravity sensor available }

Getting Sensor Information Sensor class offers methods to get sensor info getResolution() getMaximumRange() getVendor() getVersion() getMinDelay(): determines the max rate of sampling > 0: streaming sensor = 0: reporting data only when there is a change

Monitoring Sensor Events SensorEventListener onAccuracyChanged(Sensor s, int accuracy) called when the accuracy of the sensor has changed SENSOR_STATUS_ACCURACY_LOW, SENSOR_STATUS_ACCURACY_MEDIUM, SENSOR_STATUS_ACCURACY_HIGH, or SENSOR_STATUS_UNRELIABLE. onSensorChanged(SensorEvent se) Called with a SensorEvent object for new sensor data The accuracy of the data, The sensor, the timestamp of the change, and new data

Registering Listeners -1 public class SensorActivity extends Activity implements SensorEventListener {   private SensorManager mSensorManager;   private Sensor mLight;   public final void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.main);     mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);     mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);   }   public final void onAccuracyChanged(Sensor sensor, int accuracy) {     // Do something here if sensor accuracy changes.   public final void onSensorChanged(SensorEvent event) {     // The light sensor returns a single value.     // Many sensors return 3 values, one for each axis.     float lux = event.values[0];     // Do something with this sensor value. }

Registering Listeners - 2 public class SensorActivity extends Activity implements SensorEventListener { … protected void onResume() { super.onResume(); mSensorManager.registerListener(this, mLight, SensorManager.SENSOR_DELAY_NORMAL); // sample rate } protected void onPause() { super.onPause(); // if not unregistered, the sensor will continue polling data // which would drain the battery mSensorManager.unregisterListener(this); }

SensorEvent public int accuracy: public Sensor sensor: The accuracy of this event. public Sensor sensor: The sensor that generated this event. public long timestamp: The time in nanosecond at which the event happened public final float[] values: raw values of the sensor data. The length and contents of the values are sensor dependent

Sensor Coordinate System Default orientation X axis – horizontal pointing right Y axis – vertical pointing up Z axis – pointing toward the outside of the screen face. Coordinate system does not change when orientation changes You can use getOrientation() to determine screen rotation and use remapCoordinateSystem() to map sensor coordinates to screen coordinates.

Best Practices Unregister sensor listeners Unregistering listners in onPause(). Otherwise the sensor continues acquiring data Don’t test your code on the emulator Emulator cannot accurately emulate sensors Don’t block the onSensorChanged() When sensor data changes often, this method is called often. Keep it as short as possible. Avoid using deprecated methods/sensors Verify sensor’s availability before using them Not all devices provide all sensors Choose sensor delays carefully Specify the largest delay that is fast enough for your app.