Android中的计步器 [英] Step counter in Android
问题描述
最近,我尝试制作一个可以计算用户步数的应用.并遇到了Android 4.4中引入的步数和检测器.但是我找不到一种方法来按小时计数.我对此并不陌生,将不胜感激任何指导
Recently I tried to make an app which gives user step count. And came across step count and detector which was introduced in Android 4.4. but I can't find a way to do step counting hourly basis. I am new to this any guidance will be highly appreciated
我在此 https://developer.android.com/reference/android/hardware/SensorManager.html#registerListener(android.hardware.SensorEventListener ,android.hardware.Sensor,int)
I found on this https://developer.android.com/reference/android/hardware/SensorManager.html#registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int)
编辑第三个参数时,我可以在执行以下操作时指定延迟 boolean registerListener(SensorEventListener侦听器,传感器传感器,inintsamplePeriodUs)
That editing the third parameter I can specify delay while doing following boolean registerListener (SensorEventListener listener, Sensor sensor, int samplingPeriodUs)
但是它接受以毫秒为单位的值,并将一小时转换为毫秒可得到非常大的int值.谁能指导如何处理
But it accepts value in milliseconds and convert one hour into milliseconds gives a very large int value. Can anyone guide on how to deal with it
推荐答案
您正在寻找的是
这使您即使不保持设备唤醒也可以获取连续的传感器数据.它基本上将传感器事件存储在芯片本身的基于硬件的队列中,并且仅以预定义的时间间隔将其批量发送到您的应用程序(服务,..).这样,您就可以进行24/7全天候监控,而不会显着消耗电池电量.请注意,只有受支持的芯片组才能做到这一点(您可以在Android文档中找到详细信息),如果使用的是旧手机,则需要使用可怕的唤醒锁保持方法来获取数据. 源
那里是如何使用BatchStepSensor的示例 Also there is example how to use BatchStepSensor 这篇关于Android中的计步器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!