Step Detector and step Counter sensors on Android

Source: Internet
Author: User

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.

    1. 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).
    2. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.