Step counter in Android

倾然丶 夕夏残阳落幕 提交于 2020-01-14 03:38:08

问题


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

I found on this https://developer.android.com/reference/android/hardware/SensorManager.html#registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int)

That editing the third parameter I can specify delay while doing following    boolean registerListener (SensorEventListener listener,                Sensor sensor,                int samplingPeriodUs)

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


回答1:


What are you are looking for is 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. Source

Also there is example how to use BatchStepSensor



来源:https://stackoverflow.com/questions/40896558/step-counter-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!