Step Detector and step Counter sensors on Androidtime 2014-03-31 11:56:00 Tech Droid original http://techdroid.kbeanie.com/2014/03/ step-detector-and-step-counter-sensors.html
Android KitKat have added a few more hardware sensors to it ' s API list. Step sensors is one of them, which looks very promising. Although, not a lot of phones yet has these Step sensors, in the future, this would gradually become a standard I think. Currently, Nexus 5 has them.
Let's see how we can interact with these sensors. Basically, there is 2 sensors.
- Step Counter: This keeps a count of the number of steps so you have taken. The counter is only reset when you re-boot the device, else, for every step to take (or the phone thinks your took, you co Unts up).
- Step Detector: This sensor just detects if you take a step. That ' s it.
The example project shows the Initialize and setup the Sensormanager and respond to events from the Sensor S.
//Step Counter
Smanager.registerlistener (New Sensoreventlistener () {
@Override
public void Onsensorchanged (Sensorevent event) {
Float steps = event.values[0];
Textviewstepcounter.settext ((int) steps + "");
}
@Override
public void onaccuracychanged (sensor sensor, int accuracy) {
}
}, Smanager.getdefaultsensor (Sensor.type_step_counter),
SENSORMANAGER.SENSOR_DELAY_UI);
//Step Detector
Smanager.registerlistener (New Sensoreventlistener () {
@Override
public void Onsensorchanged (Sensorevent event) {
nanoseconds, convert to Millis
timestamp = event.timestamp/1000000;
}
@Override
public void onaccuracychanged (sensor sensor, int accuracy) {
}
}, Smanager.getdefaultsensor (Sensor.type_step_detector),
SENSORMANAGER.SENSOR_DELAY_UI);
No special permissions is required.