Joseph
Joseph

Reputation: 2726

Check the phone clock is correct

It is important for my Android application that the phone clock is correctly set. Is there a way to automatically check against a time server that it is correctly set, so that I can alert the user if it isn't? If not, I will just have to code it so that it checks the phones clock against my server time.

I have looked on Google but can't find anything that does what I require.

Upvotes: 1

Views: 1189

Answers (1)

slayton
slayton

Reputation: 20309

Most phones have their internal clock adjusted using the time provided by the cellular network. AFAIK there is not built in API to check the time against some time server, although it should be fairly simply to query the server of your choice to get the current time. Although you'll have to account for errors that are introduced due to amount of time it takes to query and get a response from the server. See http://en.wikipedia.org/wiki/Network_Time_Protocol

If you find that the system time is off you can always correct it using:SystemClock.setCurrentTimeMillis() although I'm not sure if this will stick or if the phone will end up re-resetting the clock using information from the cellular network.

Upvotes: 1

Related Questions