Question

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?

Était-ce utile?

La solution

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.

Autres conseils

use Handler.postDelay(runnable, timeInMillis)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top