0% found this document useful (0 votes)
21 views14 pages

Sensor

This document discusses sensors in Android devices. It describes three categories of sensors: motion sensors, environmental sensors, and position sensors. It provides details on the Android sensor framework, SensorManager class, Sensor class, sensor events, and sensor event listeners that allow accessing sensor data in Android.

Uploaded by

Misbah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views14 pages

Sensor

This document discusses sensors in Android devices. It describes three categories of sensors: motion sensors, environmental sensors, and position sensors. It provides details on the Android sensor framework, SensorManager class, Sensor class, sensor events, and sensor event listeners that allow accessing sensor data in Android.

Uploaded by

Misbah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Sensor

Lecturer
Faiz Ur Rehman
University of Mianwali
Sensors

Most of the android devices have built-in sensors that measure motion,
orientation, and various environmental condition. The android platform
supports three broad categories of sensors

Motion Sensor ( blinking light on off on call)


Environmental sensors (humidity, temp, climate measure)
Position sensors ( rotate phone angular basis )
• Motion Sensors-These sensors are useful to measure acceleration forces
and rotational forces along three axes. This category includes
accelerometers, gravity sensors, gyroscopes, and rotational vector
sensors.
• Environmental Sensors-These sensors are useful to measure various
environmental parameters, such as ambient air temperature and
pressure, illumination, and humidity. This category includes barometers,
photometers, and thermometers.
•Position Sensors-These sensors are useful to measure the physical
position of a device. This category includes orientation sensors and
magnetometers
• Android provided a framework called sensor framework to access all the
sensors available on device and to get all the raw sensor data. The sensor
framework provided a wide variety of sensor related tasks. For example, by
using sensor framework we can perform following thing
• It lists all the available sensors on the device
•It determine the capabilities of each sensor, such as its maximum range,
manufacturer, power requirements, and resolution.
•It can acquire raw sensor data and define the minimum rate at which you
acquire sensor data.
•Register and unregister sensor event listeners that monitor sensor changes.
• The Android sensor framework will allow us to access many type of
sensors, some of these sensors are hardware-based and some are
software-based.
• The Hardware-based sensors are physical components built on the
handset or tablet device and Software-based sensors are not a
physical devices but they mimic Hardware-based sensors
SensorManager
• SensorManager lets you access the device's sensors.
•The android.hardware.SensorManagerclass provides methods :
–to get sensor instance,
–to access and list sensors,
–to register and unregister sensor listeners etc.
You can get the instance of SensorManager by calling the method
getSystemService() and passing the SENSOR_SERVICE constant in it.
SensorManagers=(SensorManager)getSystemService(SENSOR_SERVICE)
;
• Class provides methods:-
to get sensor instance,
to access and list sensors,
to register and unregister sensor listeners etc.
public int getSensors ()
getSensorList()
public List<Sensor> getSensorList (int type)-
Use this method to get the list of available sensors of a certain type. Make multiple calls to get sensors of
different types or use Sensor.TYPE_ALLto get all the sensors.
•registerListener
public boolean registerListener (SensorEventListenerlistener, Sensorsensor, int samplingPeriodUs)
The rate sensor events are delivered at unregisterListener
public boolean unregisterListener (SensorEventListenerlistener, Sensor sensor)
Sensor Class
• The android.hardware.Sensorclass provides methods to get
information of the sensor such as sensor name, sensor type, sensor
resolution, sensor type etc
• Identification method
1. getype()
2. getName()
3. Getvendor()
4. Getversion()
Sensor Event class
• Its instance is created by system. It provide information about the
sensor
• 1. sensor – instance of sensor class for sensor that generated the data
• 2. values : array store any raw value from type sensor
If type is gyroscope
Event. Value[0]- acceleration along x axis
3. Accuracy flag for sensor accuracy
SensorManager.SENSOR_STATUS_ACCURACY-low
4. Timestamp : time of event in nanosecond
Sensor event listener interface
• It provide two call back method to get information when sensor
values (x, y, z) change or sensor change
• Void onaccuracychange( Sensor sensor , int accuracy)
It is called when sensor accuracy is changed
• Void onsensorchange(SensorEvent event)
• It is called when sensor values are changed.
The Sensorclass defines several constants for
accessing the different sensors
Watch video for temperature sensor
• https://www.youtube.com/watch?v=CI6sJZAKspE

You might also like