Step Detector and Step Counter Sensors on Android

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.

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


// 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); 

No special permissions are required.

Step Detector and Step Counter Sensors on Android的更多相关文章

  1. 问题:PyCharm调试方法Force Step over与step over的区别

    Force Step over与step over的差别是,后者在执行到函数时,如果函数中设置了断点,会在该函数断点处暂停,等待进一步调试指令,而Force Step over不论函数中是否有断点,都 ...

  2. step over、step into、step into my code、step out、run to cursor

    红 step over 跳过子函数 黄 step into 进入子函数 蓝 step into my code 不执行源码的子函数执行自己的 黑 step out 跳出当前函数 绿 run to cu ...

  3. Android 4.4 KitKat 新特性

    New in Android 4.4 KitKat 本文是一个概览,关于KitKat,也即Android4.4的新东西,先是功能型的,之后是设计上的. 很多特性本文并没有提到,很多提到的特性也只是简短 ...

  4. OpenCV2:Mat属性type,depth,step

    在OpenCV2中Mat类无疑使占据着核心地位的,前段时间初学OpenCV2时对Mat类有了个初步的了解,见OpenCV2:Mat初学.这几天试着用OpenCV2实现了图像缩小的两种算法:基于等间隔采 ...

  5. How to step through your code in chrome

    By executing code one line or one function at a time, you can observe changes in the data and in the ...

  6. AWS Step Function Serverless Applications

    Installing VS Components To follow along with this article, you must have an AWS account and install ...

  7. OpenCV__cv::Mat::step

    step[0]是矩阵中一行元素的字节数 step[1]是矩阵中一个元素的字节数(elemSize) step1 = step / elemSize1,elemSize1是元素的每个通道所占的字节数 s ...

  8. SoapUI Pro Project Solution Collection-Test Step Object

    Package com.eviware.soapui.model.testsuite used for access the current testsuite object, like test c ...

  9. OpenCV中对Mat里面depth,dims,channels,step,data,elemSize和数据地址计算的理解 (转)

    cv::Matdepth/dims/channels/step/data/elemSizeThe class Mat represents an n-dimensional dense numeric ...

随机推荐

  1. python tqdm函数

    tqdm是个显示进度条的库.很是方便,还有个tqdm_gui貌似可以显示GUI图像.以后有空再研究. 贴张别人的图,看一下就清楚了.

  2. 数学之美——HMM模型(二)解码和Forward算法

    上一篇讨论了HMM的基本概念和一些性质,HMM在现实中还是比较常见的,因此也带来一了一系列的HMM应用问题.HMM应用主要面向三个方面:预测.解码和学习.这篇主要讨论预测. 简单来说,预测就是给定HM ...

  3. Jupyter notebook安装与使用

    Jupyter Notebook(此前被称为 IPython notebook)是一个交互式笔记本,支持运行 40 多种编程语言. 安装 安装python 3 pip安装 pip3 install - ...

  4. web程序快速开发

    关于web程序快速开发个人见解以及经历 由于在之前公司业务的发展,需要在基于核心业务的基础上开发其他较为独立的业务系统,所以就有了这个基于Dapper,DDD概念的基础框架,由于个人基于这个框架已经经 ...

  5. 【Codechef】BB-Billboards

    题解 传说中的--半标准杨表(行单调不增,列单调减) 如果N能整除M,我们把序列分成\(\frac{N}{M}\)段 然后里面要填K个1,显然我每一段必须填K个1,且可以构造出合法的序列,所以最少要填 ...

  6. P1736 创意吃鱼法 图的DP

    题目描述 回到家中的猫猫把三桶鱼全部转移到了她那长方形大池子中,然后开始思考:到底要以何种方法吃鱼呢(猫猫就是这么可爱,吃鱼也要想好吃法 ^_*).她发现,把大池子视为01矩阵(0表示对应位置无鱼,1 ...

  7. 002.Git日常基础使用

    一 获取git仓库 1.1 初始化仓库 [root@git ~]# cd /mystudy/ [root@git mystudy]# git init [root@git mystudy]# git ...

  8. 002.iSCSI服务端配置

    一 iSCSI target的磁盘种类 大型文件 单一分区(partition) 磁盘 数组 RAID LVM 二 iSCSI创建步骤 建立用于共享的磁盘设备(分区/磁盘/文件) 创建后备磁盘 创建相 ...

  9. k8s+Jenkins+GitLab-自动化部署asp.net core项目

    0.目录 整体架构目录:ASP.NET Core分布式项目实战-目录 k8s架构目录:Kubernetes(k8s)集群部署(k8s企业级Docker容器集群管理)系列目录 此文阅读目录: 1.闲聊 ...

  10. iOS 11开发教程(十七)iOS11应用视图之使用按钮接收用户输入

    iOS 11开发教程(十七)iOS11应用视图之使用按钮接收用户输入 在iOS中提供了很多的控件以及视图来丰富用户界面,对于这些视图以及控件我们在上一章中做了简单的介绍.本章我们将详细讲解这些视图. ...