E-Book, Englisch, 194 Seiten
Nagpal Android Sensor Programming By Example
1. Auflage 2025
ISBN: 978-1-78528-466-3
Verlag: De Gruyter
Format: PDF
Kopierschutz: Adobe DRM (»Systemvoraussetzungen)
Take your Android applications to the next level of interactivity by exploring the wide variety of Android sensors
E-Book, Englisch, 194 Seiten
ISBN: 978-1-78528-466-3
Verlag: De Gruyter
Format: PDF
Kopierschutz: Adobe DRM (»Systemvoraussetzungen)
Android phones available in today's market have a wide variety of powerful and highly precise sensors. Interesting applications can be built with them such as a local weather app using weather sensors, analyzing risky driving behavior using motion sensors, a fitness tracker using step-counter sensors, and so on. Sensors in external devices such as Android Watch, Body Analyzer & Weight Machine, Running Speed Cell, and so on can also be connected and used from your Android app running on your phone.
Moving further, this book will provide the skills required to use sensors in your Android applications. It will walk you through all the fundamentals of sensors and will provide a thorough understanding of the Android Sensor Framework. You will also get to learn how to write code for the supportive infrastructure such as background services, scheduled and long running background threads, and databases for saving sensor data. Additionally, you will learn how to connect and use sensors in external devices from your Android app using the Google Fit platform.
By the end of the book, you will be well versed in the use of Android sensors and programming to build interactive applications.
Autoren/Hrsg.
Weitere Infos & Material
Motion, position, and environmental sensors
The Android platform supports mainly three broad categories of sensors: the motion, position, and environment-based sensors. This categorization is done based on the type of physical quantity detected and measured by the sensors.
Motion sensors
Motion sensors are responsible for measuring any kind of force that could potentially create motion in the , , and axes of the phone. The motion could be either a linear or angular movement in any direction. This category includes accelerometers, gravity, gyroscope, and rotational vector sensors. Most of these sensors will have values in the , , and axes, and the rotational vector will especially have extra value in the fourth axis, which is the scalar component of the rotation vector.
The following table summarizes the motion sensor usage, types, and power consumption:
| Sensor | Type | Value | Underlying Sensors | Description | Common Usage | Power Consumption |
| Accelerometer | Physical | Raw | Accelerometer | This measures the acceleration force along the , , and axes (including gravity). Unit: m/s2 | It can be used to detect motion such as shakes, swings, tilt, and physical forces applied on the phone. | Low |
| Gravity | Synthetic | Fused | Accelerometer, Gyroscope | This measures the force of gravity along the , , and axes. Unit: m/s2 | It can be used to detect when the phone is in free fall. | Medium |
| Linear Acceleration | Synthetic | Fused | Accelerometer, Gyroscope | It measures the acceleration force along the , , and axes (excluding gravity). Unit: m/s2 | It can be used to detect motion such as shakes, swings, tilt, and physical forces applied on phone. | Medium |
| Gyroscope | Physical | Raw, Calibrated | Gyroscope | This measures the rate of rotation of the device along the , , and axes. Unit: rad/s | It can be used to detect rotation motions such as spin, turn, and any angular movement of the phone. | Medium |
| Step Detector | Synthetic | Calibrated | Accelerometer | This detects walking steps. | It can be used to detect when a user starts walking. | Low |
| Step Counter | Synthetic | Calibrated | Accelerometer | It measures the number of steps taken by the user since the last reboot while the sensor was activated | It keeps track of the steps taken by the user per day. | Low |
| Significant Motion | Synthetic | Calibrated | Accelerometer | It detects when there is significant motion on the phone because of walking, running, or driving. | It detects a significant motion event. | Low |
| Rotation Vector | Synthetic | Fused | Accelerometer, Gyroscope, Magnetometer | This measures the rotation vector component along the axis (), y axis (), and axis (). Scalar component of the rotation vector (?). Unitless. | It can be used in 3D games based on phone direction. | High |
Position sensors
Position sensors are used to measure the physical position of the phone in the world's frame of reference. For example, you can use the geomagnetic field sensor in combination with the accelerometer to determine a device's position relative to the magnetic North Pole. You can use the orientation sensor to determine the device's position in your application's frame of reference. Position sensors also support values in the ,, and axes.
The following table summarizes the position sensor's usage, types, and power consumption:
| Sensor | Type | Value | Underlying Sensors | Description | Common Usage | Power Consumption |
| Magnetometer | Physical | Raw, Calibrated | Magnetometer | This measures the geomagnetic field strength along the , , and axes. Unit: µT | It can be used to create a compass and calculate true north. | Medium |
| Orientation (Deprecated) | Synthetic | Fused | Accelerometer, Gyroscope, Magnetometer | This measures the Azimuth (the angle around the axis), Pitch (the angle around the axis), and Roll (the angle around the axis). Unit: Degrees | It can be used to detect the device's position and orientation. | Medium |
| Proximity | Physical | Raw | Proximity | This measures the distance of an object relative to the view screen of a device. Unit: cm | It can be used to determine whether a handset is being held up to a person's ear. | Low |
| Game Rotation Vector | Synthetic | Fused | Accelerometer, Gyroscope | This measures the rotation vector component along the axis (?), axis (?), and axis (?). It is the scalar component of the rotation vector (?). Unitless. It is based only on the Gyroscope and Accelerometer and does not use the Magnetometer. | It can be used in 3D games based on phone direction. | Medium |
| Geomagnetic Rotation Vector | Synthetic | Fused | Accelerometer, Magnetometer | This measures the rotation vector component along the axis (), axis (?), and axis (?). It is the scalar component of the rotation vector (?). Unit less. * It is based only on the Magnetometer and Accelerometer and does not use the Gyroscope. | It can be used in augmented reality apps, which are based on the phone and compass direction. | Medium |
Environmental sensors
Environment sensors are responsible for measuring environmental properties, such as temperature, relative humidity, light, and air pressure near the phone. Unlike motion and position sensors, which give sensor values multi-dimensional arrays, the environment sensors report single sensor values.
The following table summarizes the environment sensor's usage, types, and power consumption:
| Sensor | Type | Value | Underlying Sensors | Description | Common Usage | Power Consumption |
| Ambient... |




