我有加速计读数,每次加速计值改变时,都会从onSensorChanged()函数中更新。然后,我创建一个文件,我在每一行上写加速度计读数(x,y,z)轴,但也要在每个读数之间加上时间间隔。我在某个地方读到,使用system.currenttimemillis()不是可行的方法。尽可能准确地做到这一点的最佳方法是什么?
最佳答案
我建议使用传感器事件的timestamp字段:
public long timestamp
Since: API Level 3
The time in nanosecond at which the event happened
只要记住最后一个值,然后用这种方法计算差值