Android 计步器

Step counter in Android

最近我尝试制作一个应用程序,它可以为用户提供步数。并遇到了 Android 4.4 中引入的步数和检测器。但我找不到一种每小时计算步数的方法。我是新手,非常感谢任何指导

我在这个 https://developer.android.com/reference/android/hardware/SensorManager.html#registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int)

上找到

那个编辑第三个参数我可以在做下面的事情时指定延迟 boolean registerListener (SensorEventListener listener, Sensor 传感器, int samplingPeriodUs)

但它接受以毫秒为单位的值,将一小时转换为毫秒会给出一个非常大的 int 值。任何人都可以指导如何处理它

您要找的是Sensor Batching

That allows you to get continuous sensor data even without keeping the device awake. It basically stores the sensor events in a hw based queue right in the chip itself and only sends them to your app (service,..) at predefined intervals in batches. This allows you to do a 24/7 monitoring without draining the battery significantly. Please note that only supported chipsets can do that (you can find details in Android docs), in case of older phones you need to fallback to the hideous wakelock keeping method in order to get your data.

另外 there 是如何使用 BatchStepSensor 的示例