1

My Android app requires to get the current date and time from Internet. I can't rely on the date from the phone. How is it possible to get the time from Internet? What are the available time servers?

1

3 Answers 3

1

There are a lot of time servers, the one to select would probably depend on where you are in the wold. You can find a list of the "public" ones at the NTP.org. You can get information on how you need to communicate with an NTP server from RFC958. Just an FYI, I think changing the time on the device would require ROOT permissions.

1

I have the same problem. It seems as Android have a ntp-client if you look in the logs. But it fails every time... If this had been solved, it had helped many projects/people.

As a workaround I tried this code on Android and i works. This way you can correct your local clock. (You need root access to set it)

0

The simplest is the daytime protocol assigned to port 13, but only few servers offer this (optional in e.g. Windows NT and later). What do you have available to query against?

4
  • could you please detail on the last part "what do you have available to query against?"... To be more clear, i am trying to release a limited period trial pack of my android app. Which will allow the users to use (all the features) my app free for 1 month. Since it is limited, i am hard coding a trial-offer expiry date ( do not confuse this with the 1 month trial. This, trial offer expiry date is the expiry for the apk itself) in my application code before compiling it for release.
    – Mithraa
    Jul 12, 2010 at 13:23
  • So, that users cannot uninstall my app once the trial expires and again reinstall and use it forever. When the app is run for the first time, i compare hardcoded date with date from time server ( I am planning to use time server because of the possibility that the user might tweak the phone timings himself before installing and break my security check ) to validate the apk's expiry.
    – Mithraa
    Jul 12, 2010 at 13:23
  • I have no idea about integrating my android app with the time server. Any other possibility of getting date from any other valid source other than the phone, is also welcome. BTW does google provide such a time server. Please help me.
    – Mithraa
    Jul 12, 2010 at 13:27
  • The best way to ensure that your application is not tampered with by pirates is to put some part of your application elsewhere and do online requests to get answers. A typical location for such code is the Google Application Engine which Google hosts for free until you reach a pretty high limit. In your case, this could simply be a time stamp service, but that would be too easy to hack I think Jul 12, 2010 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.