Understanding the step counter and step detector sensors
The step counter and step detector sensors are very similar to each other and are used to count the steps. Both the sensors are based on a common hardware sensor that internally uses the accelerometer, but Android still treats them as logically separate sensors. Both of these sensors are highly battery optimized and consume very little power. Now, let's look at each individual sensor in detail.
The step counter sensor
The step counter sensor is used to get the total number of steps taken by the user since the last reboot (power on) of the phone. When the phone is restarted, the value of the step counter sensor is reset to zero. In the onSensorChanged()
method, the number of steps is given by event.value[0]
; although it's a float value, the fractional part is always zero. The event timestamp represents the time at which the last step was taken. This sensor is especially useful for those applications that don't want to run in the background...