This question may be a little long, but open to many suggestions.
Problem:
We have several MyTouch devices at API level 8 (Android 2.2) MyTouch, which we will use to record acceleration data in an amusement park, namely a roller coaster. We also have a visualization function that allows us to display and view the points of the accelerometer depending on the time at which they were recorded. That's where we have the dilemma! The system times on Android devices are not all the same, and they cannot be installed at the same time accurate to the millisecond (only manually with a little accuracy, which is terrible).
Attempt Solution:
So, I first resorted to recording data in accordance with the GPS time found at the beginning of the application. A long short process: get the GPS time, get the system time, get the difference, and after recording the data point, get the system time again and add the difference back to the time, mark it as the start time of the recording and increase the item from there by 200 milliseconds for each recorded data. However, there are 2 problems (for getting GPS time):
Using getLastKnownLocation() not too accurate. In fact, this seems very inaccurate. This gives me a time that is 9 minutes from the current GMT / UTC. By the way, the system time is also about 9 minutes on an Android device ... the difference between GPS time and system time is usually from 1000 to 5000 milliseconds (1 to 5 seconds). I believe my code is wrong. I pasted it below so you can see.
requestSingleUpdate() would be great to use, as it would get a more recent location and possibly a very accurate time. Problem? Requires API level level 9 ... we donโt.
Ideas:
Here is an idea I had, though - what if I somehow pulled global time from the site and used the time drawn from there as recording time? The problem here is that I have no idea how to do this, it's just wishful thinking mine ...
Another idea - is there some kind of global getTime() function type that I just don't know about?
The reason I want Android to pull the time from a similar watch:
Imagine two people sitting on a roller coaster - one in the front seat, one on the back. When recording data, the person in front will obviously experience acceleration a little earlier than the person in the back (and we want to see this on our visualization graph). That is why it is important for millisecond accuracy that these points are recorded according to one global time.
The code:
Criteria c = new Criteria(); c.setAccuracy(Criteria.ACCURACY_FINE); if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { mLocationManager.requestLocationUpdates(mLocationManager.getBestProvider(c, true), 0, 0, AmusementPark.this); Criteria criteria = new Criteria(); String bestProvider = mLocationManager.getBestProvider(criteria, false); Location location = mLocationManager.getLastKnownLocation(bestProvider); try { gpsTime = location.getTime(); systemTime = System.currentTimeMillis(); timeDif = gpsTime - systemTime; Log.e("timedif", "GPS: " + gpsTime + ", System: " + systemTime +", Dif: " + timeDif); } catch (NullPointerException e){ } }
Update:
Here , someone offers a kind of "server" getTime() . I really like his code / answer, but what is this โserverโ and / or how do I install it if this is the best solution?