2016-09-15 57 views
0

我想從我的Android智能手機使用GraphView庫繪製光傳感器的數據。對於數據點的X軸值,我需要傳感器讀取數據的時間。獲得最準確的傳感器事件時間的最佳方法是什麼?如何獲取實時圖的Android傳感器數據時間?

+0

的[加速度計SensorEvent時間戳](http://stackoverflow.com/questions/5500765/accelerometer-sensorevent-timestamp) –

回答

0
@Override 
    public void onSensorChanged(SensorEvent event) { 
      event.timestamp // is the timestamp of event occurence 

    } 

event.timestamp是nanosecons不是毫秒,所以要小心

Source

0

您可以使用sensorEvent.timestamp 您將獲得納秒的時間。
所以,你可以使用這個 -

(System.nanoTime() - sensorEvent.timestamp)/Math.pow(10,6) 

登錄毫秒的時間!

+0

可能的複製我試圖 (System.nanoTime() - sensorEvent.timestamp)/ 1000000000L; 以秒爲單位的時間,但它給了我6個數字的負數。 –

相關問題