Sensors

Android devices may have any number of sensors. Two of these, the network and GPS sensors, were discussed in the previous chapter. However, other sensors may also be used in apps. In all, the Android platform supports about 12 sensors. However, there is no requirement that a manufacturer of an Android device include all of them. For this reason, it is good practice to always check for the presence of a sensor before attempting to use it. Sensors supported range from sensors that measure the devices’ ambient environment, including temperature, relative humidity, atmospheric pressure, magnetic field, and light level, to sensors that detect how the device is moving or rotating.

The Sensor class represents all types of sensors. Sensors are ...

Get Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.