Android Pedometer sensor

Source: Internet
Author: User

Introduction to the concept and principle of pedometer sensor

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.

Step Counter:this keeps a count of the number of steps that is 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 when to take a step. That ' s [email protected]link

Step counter Sensor

Type_step_counter: Pedometer (record history step cumulative value)

This type of sensor returns the number of steps the user has taken since the last reactivation. This value is returned as a floating-point number (the fractional part is set to 0) and is reset to zero only when the system reboots. The time stamp of the event is set to the time that the last step of the event is taken. The sensor is hardware-based and is expected to have low power consumption. If you want to keep track of long steps, do not unregister the sensor so that the count steps continue in the background even if the AP is in suspend mode, and the aggregation count wakes up when the AP is in a suspended state. The application needs to retain the registration of the sensor because the step counter does not count steps if no activation is activated. The sensor is suitable for fitness tracking applications. It is defined as a reporting_mode_on_change sensor.

Step Detector Sensor

Type_step_detector: Detector (detects each step data)

This type of sensor triggers an event per user. The only allowed return value is 1.0, and an event is generated for each step. As with any other event, a timestamp indicates when the event (here is a step) occurs, which corresponds to a high change in acceleration when the foot hits the ground. The sensor is only used to detect each individual step, for example, to perform a waypoint calculation. If you only need steps to accumulate over a period of time, please register type_step_counter. It is defined as a reporting_mode_special_trigger sensor. @link

API section
use: @link1before using the sensor, obtain the Sensormanager by system service first: Sensormanager Msensormanager=(Sensormanager) Getsystemservice (sensor_service);2, get the type of sensor we need://one-time effective step countSensor Mstepcount =msensormanager.getdefaultsensor (sensor.type_step_counter);//System Count Step cumulative valueSensor Mstepdetector =msensormanager.getdefaultsensor (sensor.type_step_detector);3, Register Listener (monitor sensor event) Msensormanager.registerlistener ( This, Mstepdetector, sensormanager.sensor_delay_fastest); Msensormanager.registerlistener ( This, Mstepcount, sensormanager.sensor_delay_fastest); PS: Cancel Registration: Msensormanager.unregisterlistener ( This, Mstepdetector); Msensormanager.unregisterlistener ( This, mstepcount);4, implement the Sensoreventlistener interface, override the method, and get the data: Select the appropriate type from the sensor event you hear, and get the data: @Override Public voidonsensorchanged (Sensorevent event) {if(Event.sensor.getType () = =Sensortypec) {            //Event.values[0] Add value for step historyTvallcount.settext (Event.values[0] + "step"); }    if(Event.sensor.getType () = =sensortyped) {        if(Event.values[0] = = 1.0) {Mdetector++; //Event.values[0] A valid step count dataTvtempcount.settext (mdetector + "step")); }    }}

Reference:

Android Pedometer Module Optimization Project application

Android-4-4-step-detector-and-counter

Android Pedometer feature-Simple implementation

Research on the function of Android pedometer based on acceleration sensor

Android Pedometer sensor

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.