SlideShare une entreprise Scribd logo
1  sur  24
Android Meetup
      @
Android Sensors
Android Sensors Overview

      
          Android Sensors:
–   Accelerometer
–   Gravity sensor
–   Linear Acceleration sensor
–   Magnetic Field sensor
–   Orientation sensor
–   Gyroscope
–   Light sensor
–   Proximity sensor
–   Temprature sensor
–   Pressure sensor
–   Other sensor
Accelerometer

    Provides the total force applied on the device.

  When device is stationary, this gives +1g (gravitational force) reading
in one axis and its components on other axes.

 Accelerometer values minus the gravity factor gives the induced
acceleration.

 Generally it is used to determine device orientation.


    The measurment unit is SI m/s2.
Accelerometer Coordinate System
Accelerometer and Gravity

 All forces acting on the device will be detected by the
accelerometers.

 F= ma

 If device is stationary we get the gravity value with zero
acceleration, which can be saperated by low pass filter.

 Can We calculate distance/speed ?
       –   D= ut + 1/2 at2

 How to seperate Gravity and linear accelereation ?

 Used in gaming to make it interactive.

 Pattern recognition. pedometer
Gravity Sensor and Linear Acceleration

    Gravity sensor is not a saparate hardware but t’s a virtual sensor
    based on the accelerometers, acceleration is removed from
    accelerometer data.

    Similarly Linear acceleration is not a saparate hardware but it is
    based on the accelerometer, gravity is removed from
    accelerometer data.
Magnetic field Sensor

    The magnetic field sensor measures the ambient magnetic field in
    the x, y, and z axes.

    The units of the magnetic field sensor are microteslas (uT). This

    sensor can detect the Earth’s magnetic field and therefore tell us
    where north is. This sensor is also referred to as the compass

    Magnetic field sensor is used in combination with accelerometer.

    The coordinate system
Orientation sensor

    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.

    There is no hardware for orientation sensor but combination of
    two sensor detrmine the orientation of device.

    Form API level 8 is is been deprecated.
Gyroscope sensor

    Gyroscopes measure the rate of rotation around an axis. When the
    device is not rotating, the sensor values will be zeroes.

    It gives us 3 value.
        –    Pitch (around X
        –    Roll (around y)
        –    Azimuth (around z)
Gyroscope Continue...

    Unfortunately gyroscope is error prone over time. As time
    goes gyroscope introduce drift in result, but by sensor
    fusion(combine accelerometer and gyroscope) results can be
    corrected and path of movment of device can be obtain
    correctly.

    The measurment unit is SI m/s2.
"Angel of rotation using
        Gyroscope(GyroRaw.java)”


   Call backs PerSecond

   Observe the readings
  
     Highly Accurate initially

   Gyro drift

    Used to build responsive games.
Light Sensor

    Located at front of mobile near to front facing camera.

    gives a reading of the light level detected by the light sensor of the
    device. As the light level changes, the sensor readings change.

    The units of the data are in SI lux units

    Range is from 0 to maximum value for sensor.
Proximity Sensor

    The proximity sensor either measures the distance that some object
    is from the device (in centimeters) or represents a flag to say
    whether an object is close or far.

    Some proximity sensors will give a value ranging from 0.0 to the
    maximum in increments, while others return either 0.0 or he
    maximum value only.

    Interesting fact about proximity sensors : the proximity sensor is
    sometimes the same hardware as the light sensor. Android still
    treats them as logically separate sensors.
Temprature Sensor

    The old temperature sensor provided a temperature reading and
    also returned just a single value in values[0]. This sensor usually
    read an internal temperature, such as at the battery. Till API level 13

    From API level 14 it is replaced by
    TYPE_AMBIENT_TEMPERATURE.

    The new sensor tell us about the room temprature in degree
    Celsius.
Pressure sensor

    This sensor measures barometric pressure, which could
    detect altitude can be used for weather predictions.

    The unit of measurement for a pressure sensor is atmospheric
    pressure in hPa (millibar).
Other Sensor

    Rotation Vector
    
        The rotation vector represents the orientation of the device
        as a combination of an angle and an axis, in which the
        device has rotated through an angle θ around an axis (x, y,
        or z).

    Humidity sensor
    
        Measures the relative ambient humidity in percent (%).
Sensor fusion

    Sensor fusion is a technique to filter the data and obtain the result
    by combining two or more sensor's data.



    Well known algorithem for sensor fusion
    −   Kalman filter alogrithem
    −   Complimentary filter algorithem
Measures Device's Angle by Accelerometer

    Generally Accelerometer use for measure device rotation around
    axis(x, y, or z).

    By Combining of Accelerometer orientation sensor and magnetic
    field sensor correct device orientation can be obtain.

    Android sensor framwork provide methods like getRotationMatrix()
    and getOrientationMatrix() which tell us the device rotation reltive to
    ground on all axis.

    Earth Coordinate System
Sensor Framework

    Android has provided sensor Framework
    managed by following classes
    −   Sensor
    −   SensorManager
    −   SensorEvent
    −   SensorEventListener

    Framework has provided call back to obtain
    sensor data.
SensorFramework continue...

    SensorEventListener async       Your App               SensorManager

    call back                                  Register Callback


    Call back retrive data at
    different duration                          Sensor Event

                                                 Sensor Event
    −   Normal 20mS
    −   Game 20mS                                Sensor Event

    −   Fast 0mS

    Accuracy of rerieved data can
    be Low,Medium or High
Sensor example
public class SensorActivity extends Activity implements
                 SensorEventListener {

          private SensorManager mSensorManager;
                 private Sensor mLight;

                        @Override
 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);
                            }
SensorEventListener call back
                           @Override
public final void onAccuracyChanged(Sensor sensor, int accuracy) {
          // Do something here if sensor accuracy changes.
                                }

                            @Override
      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];
                                }
Good Habits for sensors
                @Override
        protected void onResume() {
              super.onResume();
mSensorManager.registerListener(this, mLight,
   SensorManager.SENSOR_DELAY_NORMAL);
                     }

                 @Override
        protected void onPause() {
              super.onPause();
  mSensorManager.unregisterListener(this);
                      }
                    }

Contenu connexe

Tendances

android layouts
android layoutsandroid layouts
android layouts
Deepa Rani
 
Android animation
Android animationAndroid animation
Android animation
Krazy Koder
 
Android notification
Android notificationAndroid notification
Android notification
Krazy Koder
 

Tendances (20)

Location-Based Services on Android
Location-Based Services on AndroidLocation-Based Services on Android
Location-Based Services on Android
 
Android Lesson 3 - Intent
Android Lesson 3 - IntentAndroid Lesson 3 - Intent
Android Lesson 3 - Intent
 
Notification android
Notification androidNotification android
Notification android
 
Sensors on android
Sensors on androidSensors on android
Sensors on android
 
android layouts
android layoutsandroid layouts
android layouts
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Android
 
Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming Basics
 
Android animation
Android animationAndroid animation
Android animation
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
Android notification
Android notificationAndroid notification
Android notification
 
Publishing and delivery of mobile application
Publishing and delivery of mobile applicationPublishing and delivery of mobile application
Publishing and delivery of mobile application
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
Android SDK Tutorial | Edureka
Android SDK Tutorial | EdurekaAndroid SDK Tutorial | Edureka
Android SDK Tutorial | Edureka
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
Android Application Development
Android Application DevelopmentAndroid Application Development
Android Application Development
 
05 intent
05 intent05 intent
05 intent
 
Android Data Persistence
Android Data PersistenceAndroid Data Persistence
Android Data Persistence
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycle
 
Android gps, location services, camera and sensors - Paramvir Singh
Android gps, location services, camera and sensors - Paramvir SinghAndroid gps, location services, camera and sensors - Paramvir Singh
Android gps, location services, camera and sensors - Paramvir Singh
 
Basics and different xml files used in android
Basics and different xml files used in androidBasics and different xml files used in android
Basics and different xml files used in android
 

En vedette

Sensors and their applications
Sensors and their applicationsSensors and their applications
Sensors and their applications
nitigga92
 
Smart Systems and The Future of Smart Products_ Group 4_FinalPaper (1)
Smart Systems and The Future of Smart Products_ Group 4_FinalPaper (1)Smart Systems and The Future of Smart Products_ Group 4_FinalPaper (1)
Smart Systems and The Future of Smart Products_ Group 4_FinalPaper (1)
Michael Hanacek
 

En vedette (20)

Android Sensor
Android SensorAndroid Sensor
Android Sensor
 
Smartphone sensor and gesture
Smartphone sensor and gestureSmartphone sensor and gesture
Smartphone sensor and gesture
 
Sensor's inside
Sensor's insideSensor's inside
Sensor's inside
 
Android Sensor System
Android Sensor SystemAndroid Sensor System
Android Sensor System
 
Android - Sensor Manager
Android - Sensor ManagerAndroid - Sensor Manager
Android - Sensor Manager
 
Sensors and their applications
Sensors and their applicationsSensors and their applications
Sensors and their applications
 
Sensors
SensorsSensors
Sensors
 
Android Sensor and Framework - AWARE
Android Sensor and  Framework - AWAREAndroid Sensor and  Framework - AWARE
Android Sensor and Framework - AWARE
 
Sensors and location based services
Sensors and location based servicesSensors and location based services
Sensors and location based services
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Proximity Sensors
Proximity SensorsProximity Sensors
Proximity Sensors
 
Magnetic field sensing
Magnetic field sensingMagnetic field sensing
Magnetic field sensing
 
Proximity sensors
Proximity sensorsProximity sensors
Proximity sensors
 
Top sensors inside the smartphone you want to know
Top sensors inside the smartphone you want to knowTop sensors inside the smartphone you want to know
Top sensors inside the smartphone you want to know
 
Factual writing
Factual writingFactual writing
Factual writing
 
Collaborative Sensor Rotation Programme Jacqueline Barr (IBI Group)
Collaborative Sensor Rotation Programme Jacqueline Barr (IBI Group)Collaborative Sensor Rotation Programme Jacqueline Barr (IBI Group)
Collaborative Sensor Rotation Programme Jacqueline Barr (IBI Group)
 
Peno sensor
Peno sensorPeno sensor
Peno sensor
 
Bridging the Competency Gap with eLearning
Bridging the Competency Gap with eLearningBridging the Competency Gap with eLearning
Bridging the Competency Gap with eLearning
 
Smart Systems and The Future of Smart Products_ Group 4_FinalPaper (1)
Smart Systems and The Future of Smart Products_ Group 4_FinalPaper (1)Smart Systems and The Future of Smart Products_ Group 4_FinalPaper (1)
Smart Systems and The Future of Smart Products_ Group 4_FinalPaper (1)
 
Using Hardware Security with Android Apps
Using Hardware Security with Android AppsUsing Hardware Security with Android Apps
Using Hardware Security with Android Apps
 

Similaire à Android sensors

Automatic Altitude Control of Quadroto3
Automatic Altitude Control of Quadroto3Automatic Altitude Control of Quadroto3
Automatic Altitude Control of Quadroto3
isaac chang
 
S2 7 edm & total stations
S2 7 edm & total stationsS2 7 edm & total stations
S2 7 edm & total stations
Est
 

Similaire à Android sensors (20)

Week12.pdf
Week12.pdfWeek12.pdf
Week12.pdf
 
Sensing Mobile Devices talk from QCon London 2013
Sensing Mobile Devices talk from QCon London 2013Sensing Mobile Devices talk from QCon London 2013
Sensing Mobile Devices talk from QCon London 2013
 
Android Training (Sensors)
Android Training (Sensors)Android Training (Sensors)
Android Training (Sensors)
 
Tk2323 lecture 10 sensor
Tk2323 lecture 10   sensorTk2323 lecture 10   sensor
Tk2323 lecture 10 sensor
 
Generic sensors for the Web
Generic sensors for the WebGeneric sensors for the Web
Generic sensors for the Web
 
iwatchjr | Mobile Handset Sensors Coordinate System
iwatchjr | Mobile Handset Sensors Coordinate Systemiwatchjr | Mobile Handset Sensors Coordinate System
iwatchjr | Mobile Handset Sensors Coordinate System
 
Smart Phone Sensor
Smart Phone SensorSmart Phone Sensor
Smart Phone Sensor
 
Sensor android
Sensor androidSensor android
Sensor android
 
Sensors Unit IV.pptx
Sensors Unit IV.pptxSensors Unit IV.pptx
Sensors Unit IV.pptx
 
Sensors 9
Sensors   9Sensors   9
Sensors 9
 
Sensors
SensorsSensors
Sensors
 
Robotics unit3 sensors
Robotics unit3 sensorsRobotics unit3 sensors
Robotics unit3 sensors
 
roboticsunit3sensors and -201013084413.pptx
roboticsunit3sensors and -201013084413.pptxroboticsunit3sensors and -201013084413.pptx
roboticsunit3sensors and -201013084413.pptx
 
Android sensor
Android sensorAndroid sensor
Android sensor
 
Smart sensors
Smart sensorsSmart sensors
Smart sensors
 
Sensors-and-Actuators-working principle and types of sensors
Sensors-and-Actuators-working principle and types of sensorsSensors-and-Actuators-working principle and types of sensors
Sensors-and-Actuators-working principle and types of sensors
 
RMV sensors
RMV sensorsRMV sensors
RMV sensors
 
Automatic Altitude Control of Quadroto3
Automatic Altitude Control of Quadroto3Automatic Altitude Control of Quadroto3
Automatic Altitude Control of Quadroto3
 
Base sensor
Base sensorBase sensor
Base sensor
 
S2 7 edm & total stations
S2 7 edm & total stationsS2 7 edm & total stations
S2 7 edm & total stations
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

Android sensors

  • 3. Android Sensors Overview  Android Sensors: – Accelerometer – Gravity sensor – Linear Acceleration sensor – Magnetic Field sensor – Orientation sensor – Gyroscope – Light sensor – Proximity sensor – Temprature sensor – Pressure sensor – Other sensor
  • 4. Accelerometer  Provides the total force applied on the device.  When device is stationary, this gives +1g (gravitational force) reading in one axis and its components on other axes.  Accelerometer values minus the gravity factor gives the induced acceleration.  Generally it is used to determine device orientation.  The measurment unit is SI m/s2.
  • 6. Accelerometer and Gravity  All forces acting on the device will be detected by the accelerometers.  F= ma  If device is stationary we get the gravity value with zero acceleration, which can be saperated by low pass filter.  Can We calculate distance/speed ? – D= ut + 1/2 at2  How to seperate Gravity and linear accelereation ?  Used in gaming to make it interactive.  Pattern recognition. pedometer
  • 7. Gravity Sensor and Linear Acceleration  Gravity sensor is not a saparate hardware but t’s a virtual sensor based on the accelerometers, acceleration is removed from accelerometer data.  Similarly Linear acceleration is not a saparate hardware but it is based on the accelerometer, gravity is removed from accelerometer data.
  • 8. Magnetic field Sensor  The magnetic field sensor measures the ambient magnetic field in the x, y, and z axes.  The units of the magnetic field sensor are microteslas (uT). This  sensor can detect the Earth’s magnetic field and therefore tell us where north is. This sensor is also referred to as the compass  Magnetic field sensor is used in combination with accelerometer.  The coordinate system
  • 9. Orientation sensor  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.  There is no hardware for orientation sensor but combination of two sensor detrmine the orientation of device.  Form API level 8 is is been deprecated.
  • 10. Gyroscope sensor  Gyroscopes measure the rate of rotation around an axis. When the device is not rotating, the sensor values will be zeroes.  It gives us 3 value. – Pitch (around X – Roll (around y) – Azimuth (around z)
  • 11. Gyroscope Continue...  Unfortunately gyroscope is error prone over time. As time goes gyroscope introduce drift in result, but by sensor fusion(combine accelerometer and gyroscope) results can be corrected and path of movment of device can be obtain correctly.  The measurment unit is SI m/s2.
  • 12. "Angel of rotation using Gyroscope(GyroRaw.java)”  Call backs PerSecond  Observe the readings  Highly Accurate initially  Gyro drift  Used to build responsive games.
  • 13. Light Sensor  Located at front of mobile near to front facing camera.  gives a reading of the light level detected by the light sensor of the device. As the light level changes, the sensor readings change.  The units of the data are in SI lux units  Range is from 0 to maximum value for sensor.
  • 14. Proximity Sensor  The proximity sensor either measures the distance that some object is from the device (in centimeters) or represents a flag to say whether an object is close or far.  Some proximity sensors will give a value ranging from 0.0 to the maximum in increments, while others return either 0.0 or he maximum value only.  Interesting fact about proximity sensors : the proximity sensor is sometimes the same hardware as the light sensor. Android still treats them as logically separate sensors.
  • 15. Temprature Sensor  The old temperature sensor provided a temperature reading and also returned just a single value in values[0]. This sensor usually read an internal temperature, such as at the battery. Till API level 13  From API level 14 it is replaced by TYPE_AMBIENT_TEMPERATURE.  The new sensor tell us about the room temprature in degree Celsius.
  • 16. Pressure sensor  This sensor measures barometric pressure, which could detect altitude can be used for weather predictions.  The unit of measurement for a pressure sensor is atmospheric pressure in hPa (millibar).
  • 17. Other Sensor  Rotation Vector  The rotation vector represents the orientation of the device as a combination of an angle and an axis, in which the device has rotated through an angle θ around an axis (x, y, or z).  Humidity sensor  Measures the relative ambient humidity in percent (%).
  • 18. Sensor fusion  Sensor fusion is a technique to filter the data and obtain the result by combining two or more sensor's data.  Well known algorithem for sensor fusion − Kalman filter alogrithem − Complimentary filter algorithem
  • 19. Measures Device's Angle by Accelerometer  Generally Accelerometer use for measure device rotation around axis(x, y, or z).  By Combining of Accelerometer orientation sensor and magnetic field sensor correct device orientation can be obtain.  Android sensor framwork provide methods like getRotationMatrix() and getOrientationMatrix() which tell us the device rotation reltive to ground on all axis.  Earth Coordinate System
  • 20. Sensor Framework  Android has provided sensor Framework managed by following classes − Sensor − SensorManager − SensorEvent − SensorEventListener  Framework has provided call back to obtain sensor data.
  • 21. SensorFramework continue...  SensorEventListener async Your App SensorManager call back Register Callback  Call back retrive data at different duration Sensor Event Sensor Event − Normal 20mS − Game 20mS Sensor Event − Fast 0mS  Accuracy of rerieved data can be Low,Medium or High
  • 22. Sensor example public class SensorActivity extends Activity implements SensorEventListener { private SensorManager mSensorManager; private Sensor mLight; @Override 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); }
  • 23. SensorEventListener call back @Override public final void onAccuracyChanged(Sensor sensor, int accuracy) { // Do something here if sensor accuracy changes. } @Override 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]; }
  • 24. Good Habits for sensors @Override protected void onResume() { super.onResume(); mSensorManager.registerListener(this, mLight, SensorManager.SENSOR_DELAY_NORMAL); } @Override protected void onPause() { super.onPause(); mSensorManager.unregisterListener(this); } }