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

前端 未结 5 1923
说谎
说谎 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 14:04

    You can change the interval by changing the delay when registering for the sensor.

    int SENSOR_DELAY_FASTEST    get sensor data as fast as possible 
    int SENSOR_DELAY_GAME       rate suitable for games 
    int SENSOR_DELAY_NORMAL     rate (default) suitable for screen orientation changes
    int SENSOR_DELAY_UI         rate suitable for the user interface
    

    According to this, the Fastest delay is what you would need and if it doesn't changes fast enough for you is because there were no changes. There is no getSensorData method.

    You can specify other data delays, such as SENSOR_DELAY_GAME (20,000 microsecond delay), SENSOR_DELAY_UI (60,000 microsecond delay), or SENSOR_DELAY_FASTEST (0 microsecond delay). As of Android 3.0 (API Level 11) you can also specify the delay as an absolute value (in microseconds).

    The delay that you specify is only a suggested delay. The Android system and other applications can alter this delay. As a best practice, you should specify the largest delay that you can because the system typically uses a smaller delay than the one you specify (that is, you should choose the slowest sampling rate that still meets the needs of your application). Using a larger delay imposes a lower load on the processor and therefore uses less power.

提交回复
热议问题