The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.
“Sensors” is Android’s overall term for ways that Android can detect elements of the physical world around it, from magnetic flux to the movement of the device. Not all devices will have all possible sensors, and other sensors are likely to be added over time. In this chapter, we will explore the general concept of Android sensors and how to receive data from them.
Note, however, that this chapter will not get into details of detecting movement via the accelerometer, etc.
Understanding this chapter requires that you have read the core chapters,
particularly the chapter on threads. Having experience
with other system-service-and-listener patterns, such as
fetching locations with
LocationManager, is helpful
but not strictly required.
When fetching locations from
LocationManager, you do not have dedicated APIs
per location-finding technology (e.g., GPS vs. WiFi hotspot proximity vs.
cell-tower triangulation vs. …). Instead, you work with a
system service, asking for locations using a single API, where location
technologies are identified by name (e.g.,
Similarly, when working with sensors, you do not have dedicated APIs to get
sensor readings from each sensor. Instead, you work with a
system service, asking for sensor events using a single API, where sensors
are identified by name (e.g.,
Note, though, that there are some dedicated methods on
help you interpret some of the sensors, particularly the accelerometer.
However, those are merely helper methods; getting at the actual accelerometer
data uses the same APIs that you would use to, say, access the barometer for
The preview of this section was lost in the sofa cushions.
The preview of this section is off trying to sweet-talk the Khaleesi into providing us with a dragon.
The preview of this section was lost due to a rupture in the space-time continuum.