There is an onSensorChanged(SensorEvent event) listener for android sensor. But this is triggered whenever this is a tiny change in the sensor data. How can I check the sensor reading every 0.5s instead of whenever the sensor data has changed?

有帮助吗?

解决方案

I'm afraid you can not set the interval that the callback will be triggered since even passing SensorManager.SENSOR_DELAY_NORMAL parameter will cause it to trigger more than once every half second. Check the values for SENSOR_DELAY below.

SENSOR_DELAY_UI (60,000 microsecond delay)

SENSOR_DELAY_FASTEST (0 microsecond delay)

SENSOR_DELAY_NORMAL) (200,000 microseconds delay)

So, you will receive callbacks every 0.2 seconds and implement your way to DoYourProcedure() once every 2.5 ticks.

其他提示

use Handler.postDelay(runnable, timeInMillis)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top