5

I'm developing an app that needs to control real time in any location on the Earth and do something when time comes. At the same time not to rely on system time because user can easily change it.
Does anybody have an experience of implementing "sntp/ntp" service on android device or is there any other solution to do it? Thanks

Maxim
  • 4,152
  • 8
  • 50
  • 77
  • Any location on the earth?? Think about what you're saying here, then get a satcom phone. – devin Jun 21 '12 at 13:43
  • @devin Think about how it can be done without satcom phone. GPS position you can get pretty everywhere. If you're able to send coordinates to a service that can find out your time zone by coordinates and send back local time for that zone you are done. I did it using geonames service. :-P – Maxim Jun 21 '12 at 13:57

1 Answers1

12

Check out the SNTP client code at:

https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/net/SntpClient.java

Dick Lucas
  • 12,289
  • 14
  • 49
  • 76
Brandon E Taylor
  • 24,881
  • 6
  • 47
  • 71
  • Any tip which host I can use? Tried with "pool.ntp.org" and "0.pool.ntp.org", get "android.os.NetworkOnMainThreadException" when try to get host by name. – Maxim Oct 06 '11 at 18:52
  • 4
    From the Honeycomb release forward, you cannot do a network operation in the main thread. Check out: http://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception – Brandon E Taylor Oct 06 '11 at 19:21
  • Yeah, right, already had that issue before and forgot. Works perfect now. Thanks. – Maxim Oct 07 '11 at 15:16
  • 2
    That is the SNTP client from the Android source; [here is](http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/android/net/SntpClient.java/) a more up-to-date version. – Tom Jan 26 '13 at 19:37