public static final int TYPE_STEP_DETECTOR = 18; 
 public static final int TYPE_STEP_COUNTER = 19; 

计步器Feature: 

./native/data/etc/android.hardware.sensor.stepdetector.xml:17 
./native/data/etc/android.hardware.sensor.stepcounter.xml:17: 
    

两种计步器的区别和特点: 

TYPE_STEP_DETECTOR 
This sensor triggers an event each time the user takes a step. Upon each user step, this sensor delivers an event with a value of 1.0 and a timestamp indicating when the step occurred. 

TYPE_STEP_COUNTER 
This sensor also triggers an event upon each detected step, but instead delivers the total accumulated number of steps since this sensor was first registered by an app. 
Be aware that these two step sensors don't always deliver the same results. The TYPE_STEP_COUNTER events occur with a higher latency than those from TYPE_STEP_DETECTOR, but that's because the TYPE_STEP_COUNTER algorithm does more processing to eliminate false positives. So the TYPE_STEP_COUNTER may be slower to deliver events, but its results should be more accurate.




Android KitKat has added a few more hardware sensors to it's API list. Step Sensors are one of them, which looks very promising. Although, not a lot of phones yet have 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 are 2 sensors.  
Step Counter: This keeps a count of the number of steps that you have taken. The counter is only reset when you re-boot the device, else, for every step you take (or the phone thinks you took, you counts up). 

Step Detector: This sensor just detects when you take a step. That's it.  

=====================================================

两种计步器实例代码: 

The example project shows you how to initialize and setup the SensorManager and respond to events from the Sensors. 

   sManager = (SensorManager) getSystemService(SENSOR_SERVICE); 
// 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) {  
// Time is in 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);  




    mStepCounter = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER); 
    mStepDetector = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR); 
    mUiHandler = new Handler(Looper.getMainLooper()); 


===============================




更多相关文章

  1. Android(安卓)AsyncTask实例
  2. Android笔记 SystemUI
  3. android skia 使用实例
  4. 【android-tips】android程序执行adb shell命令(实例源码)
  5. android 入门demo menu
  6. Android那些疑惑(2)-LayoutInflater中inflate方法参数的意义
  7. Android(安卓)View之组合控件实例(一)
  8. android 开发实例底部导航(1)
  9. Android中回调接口使用实例

随机推荐

  1. android隐藏软键盘
  2. [置顶] android系统功能调用大全
  3. Android(安卓)如何实现竖排文字显示?
  4. Running GPS positioning in a backgroun
  5. android 测试Activity,Content Provider,
  6. [android]gsm smsmessage 类部分详解
  7. Android(安卓)Menu菜单的编写及事件响应
  8. android retrofit2 如何多文件上传
  9. android中读取assets中的文件
  10. 通过adb shell命令查看当前与用户交互的