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

Chapter 7b - Sensors

The document discusses different types of sensors available on Android devices including motion, environmental and position sensors. It describes how to access raw sensor data from these sensors and lists some common sensors like accelerometer, gyroscope, light sensor etc. It also provides code examples to get sensor data in Flutter apps using plugins.

Uploaded by

manar ahmed
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 views32 pages

Chapter 7b - Sensors

The document discusses different types of sensors available on Android devices including motion, environmental and position sensors. It describes how to access raw sensor data from these sensors and lists some common sensors like accelerometer, gyroscope, light sensor etc. It also provides code examples to get sensor data in Flutter apps using plugins.

Uploaded by

manar ahmed
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/ 32

Chapter 7b: Sensor (Android Devices)

SKR4307
SEMESTER I 2022/23
1. Introduction

 Android-powered devices – have built-in sensors that measure motion,


orientation, and environmental conditions such as ambient light or
temperature.
 These sensors provide data to the app with high precision and accuracy.
 E.g. – a game might track readings from a device's accelerometer sensor
to infer complex user gestures and motions, such as tilt, shake, or
rotation.
… cont.
 Provide the measurements of certain properties:
• Device motion,
• Orientation and rotation,
• Pressure,
• Temperature,
• Light,
• Magnetic field,
• Proximity and humidity.
 Android sensor framework – can implement in android app the features
that use sensors and its raw data.
sensors – Flutter plugin to access the accelerometer
and gyroscope sensors.
 Expose 3 classes of sensor events, through three different streams.
• AccelerometerEvents – describe the velocity of the device, including the
effects of gravity. Put simply, use accelerometer readings to tell if the device is
moving in a particular direction.
• UserAccelerometerEvents – describe the velocity of the device, but don't
include gravity. They can also be thought of as just the user's affect on the device.
• GyroscopeEvents – describe the rotation of the device.

 Each is exposed through


a BroadcastStream: accelerometerEvents, userAccelerometerEvent
s, and gyroscopeEvents.
Sensors of Smart Devices in the Internet of Everything (IoE) Era: Big
Opportunities and Massive Doubts
https://www.hindawi.com/journals/js/2019/6514520/

Smart Device Architecture


2. Sensor types

 3 categories – based on the type of


the properties they measure (either
hardware or software):
i. Motion
ii. Environmental
iii. Position
 Software based sensors – use
hardware sensors to provide
measurement of a parameter.
2.1 Motion sensor
 Useful for monitoring device movement, such as tilt,
shake, rotation, or swing.
 Movement is usually a reflection of:
• Direct user input (e.g., a user steering a car in a
game or a user controlling a ball in a game), or
• Physical environment in which the device is
sitting (e.g.., moving while drive the car).
 Direct user input – monitoring motion relative to the
device's frame of reference or your application's
frame of reference;
 Physical environment – monitoring motion relative
to the world's frame of reference.
… cont.

 Not typically used to monitor device position, but they can be used with
other sensors, such as the geomagnetic field sensor – to determine a
device's position relative to the world's frame of reference (coordinate
system).
 Measure acceleration and rotational forces along three axes.
• Accelerometer – measuring shake, tilt, etc.,
• Proximity sensor – measuring proximity of an object relative to the
screen of the device, gyroscope for measuring spin, turn, etc.,
• Gravity sensor – measuring force of gravity and rotational vector for
measuring device orientation.
 All motion sensors return multi-
dimensional arrays of sensor values for
… cont. each SensorEvent.
 E.g., during a single sensor event the
accelerometer returns acceleration force
data for the three coordinate axes, and
the gyroscope returns rate of rotation
data for the three coordinate axes.
2.2 Environmental sensor

 FOUR sensors that let monitor various environmental properties.


• Light, Pressure, Temperature, Humidity
 These sensors can monitor relative ambient humidity, illuminance,
ambient pressure, and ambient temperature near an Android-powered
device.
 All sensors are hardware-based – available only if a device manufacturer
has built them into a device.
Environment sensors return a single sensor
value for each data event.

E.g., the temperature in °C or the pressure in


… cont. hPa.

Also, unlike motion sensors and position


sensors, which often require high-pass or low-
pass filtering – environment sensors do not
typically require any data filtering or data
processing.
 Measure environmental properties such as
temperature, pressure, light, humidity.
… cont.  E.g., thermometer (humidity), barometer
(pressure), photometer (brightness).
2.3 Position sensor

 Android platform – two sensors to position of a device:


i. Geomagnetic
ii. Accelerometer
 Provides a sensor – determine how close the face of a device is to an
object – proximity sensor.
 Geomagnetic field sensor & the proximity sensor – hardware-based.
• In most handset and tablet manufacturers
Sensor.TYPE_ACCELEROMETER
… cont.

Likewise, handset manufacturers usually include a proximity sensor to determine


when a handset is being held close to a user's face (for example, during a phone
call).
To determine a device's orientation – can use the readings from the device's
accelerometer and the geomagnetic field sensor.

Position sensors – useful for determining a device's physical position in the world's
frame of reference.
• E.g., can use the geomagnetic field sensor in combination with the accelerometer
to determine a device's position relative to the magnetic north pole.
… cont.

 Position sensors – not typically used to monitor device movement or


motion, such as shake, tilt, or thrust.
 Geomagnetic field sensor and accelerometer – return multi-dimensional
arrays of sensor values for each SensorEvent.
• E.g., the geomagnetic field sensor provides geomagnetic field strength values for
each of the three coordinate axes during a single sensor event.
3. List of sensors on a device

 Android SensorManager method – can get list of all available sensors on a


device by calling getSensorList on SensorManager object passing sensor
type all argument to it.
 The method returns list of Sensor objects – can get sensor type, name, vendor, power,
delay between sensor events and maximum range, etc.
SensorManager sensorManager =
(SensorManager)getSystemService(Context.SENSOR_SERVICE);
List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL); String
sensorInfo = "";
for (Sensor s : sensorList){
sensorInfo= sensorInfo + s.getName()+ "\n";
}
textView.setText(sensorInfo);
3.1 flutter_sensors 0.1.6

 Simple sensor event listener plugin for flutter(Android & iOS)


 Installation – add the plugin in the project (pubspec.yaml)
… cont.

 iOS – add the following key-value pair into Info.plist file inside
the ios/Runner folder in the project.
… cont.

 Register a new listener for a specific sensor:


… cont.

 Check if a specific sensor is available.

 Remember to cancel StreamSubscriptions after done with the


sensor updates
Get gyroscope sensor data in flutter app

 sensor_plus plugin

https://www.fluttercampus.com/guide/283/get-gyroscope-sensor-data
-flutter/
Smartphone movement speedometer

 https://www.flutterclutter.dev/flut
ter/tutorials/smartphone-moveme
nt-speedometer/2020/1685/
https://pub.dev/packages/flutter_sensors/example
References

i. https://www.javatpoint.com/android-sensor-tutorial
ii. https://www.zoftino.com/android-sensors-examples

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy