Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: GPS timestamp vs. SensorEvent Timestamp

I just realised that on android the timestamps you get from a GPS Location update are in ms since epoch whereas the timestamps of SensorEvent updates(e.g. of the Accelerometer) are in ns since startup.

I would like to convert the GPS timestamps to the format of the SensorEvent timestamps, does anyone know a good method to do this?

I tried the following: I measured once the time of system startup since epoch:

startupTime = System.currentTimeMillis() - SystemClock.uptimeMillis();

For each gps location update I subtract the startup time:

timestamp = loc.getTime() - startupTime;

But those converted timestamps do still not conform to SensorEvent timestamps, there is still a difference of a couple of seconds...

like image 811
user1086105 Avatar asked Dec 29 '25 20:12

user1086105


1 Answers

Do not use SystemClock.uptimeMillis(), since it measures the time since boot without the time where the device was in sleep mode. Instead use SystemClock.elapsedRealtime().

like image 134
Tobias Avatar answered Dec 31 '25 08:12

Tobias