How to log data from Android Motion Sensors at a fixed rate

前端 未结 5 1924
说谎
说谎 2020-12-31 13:47

I\'m learning the Basics of Android programming.

I have a simple android test application in which i log the accelerometer,magnetometer and the orientation data to a

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 13:58

    When registering your Listener with the SensorManager using registerListener, instead of the fixed constants SENSOR_DELAY_... you can pass the interval in microseconds as described in the JavaDocs:

    rate The rate sensor events are delivered at. This is only a hint to the system. Events may be received faster or slower than the specified rate. Usually events are received faster. The value must be one of SENSOR_DELAY_NORMAL, SENSOR_DELAY_UI, SENSOR_DELAY_GAME, or SENSOR_DELAY_FASTEST or, the desired delay between events in microsecond.

    So, just pass 40000 to match your example request, also, as stated, this in only a hint so I would not rely on getting the values in intervals exact to the microseconds.

提交回复
热议问题