Getting sensor values per second

13,176

Solution 1

The delay specified by SENSOR_DELAY_* is only a suggested delay, actual results might come faster or slower. If you only need one reading per second you can use the slowest rate (SENSOR_DELAY_NORMAL), it should update about 5 times per second. You'll need your own timing if you want to do something exactly once per second, though.

http://developer.android.com/guide/topics/sensors/sensors_overview.html

Solution 2

thank you, it answered my question, too, i was using 1000, seems like the values are in micro seconds.

 SENSOR_DELAY_UI      (60,000 microsecond delay)
 SENSOR_DELAY_FASTEST (0 microsecond delay)
 SENSOR_DELAY_NORMAL) (200,000 microseconds delay)

so for one second i should use a constant 1,000,000 micro seconds.

Share:
13,176
Laurence Nicolaou
Author by

Laurence Nicolaou

I joined this forum, so I can learn and discuss problem that occur. I hate when users just downgrade a question without even commenting why it's not a good question. We are all in this forum to help each other and it's not a popularity contest.

Updated on June 09, 2022

Comments

  • Laurence Nicolaou
    Laurence Nicolaou about 2 years

    Is there any way that I can get the sensor reading per second? what is SENSOR_DELAY_NORMAL rate in seconds?

    sm=(SensorManager)getSystemService(SENSOR_SERVICE);
    accelerometer=sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    sm.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);