Sync Android devices via GPS time?

夙愿已清 提交于 2019-11-27 13:12:22

You can get the time difference in milliseconds from currentTimeMillis() and Location.getTime() in the onLocationChanged() callback. Use requestSingleUpdate()


I just want to add that, if the user has a data connection they can use NTP time, which is even more accurate, as the GPS internal clock might drift and correcting it takes a while.


EDIT: I want to edit this answer. After working as a GNSS developer in Android OS I realized that many 'major' Android OEMs have messed this up. Usually NMEA sentences are generated at the chipset or GNSS stack. Sometimes the time is right, it depends on the implementation.

Also there is a problem of leap second. GPS time is not UTC time. And as of this writing it is 18 seconds ahead.

Also GPS time fromLocation objects are now system time as per the documentation

TLDR : use NTP time

muneikh

You cannot rely totally on the GPS time as there is a known issue for some devices that the time retrieved for some devices is one day ahead. In that case you might get a big offset.

http://code.google.com/p/android/issues/detail?id=23937

A workaround for solving this issue has been discussed here: Android : Samsung Galaxy Tabs and Android 2.2 Devices Showing GPS date 1 Day Advance from 1st jan 2012

UTC is not derived from GPS, APK overrides GPS. Android set to ignore GPS clock. You are getTime() is NIST. not GPS

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!