Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making the user change the time in Android

Tags:

android

time

Android doesn't appear to provide a way for a user application to change the system time. What I would like to do instead is to get the user to change the time. It is easy to open up the Date & Time settings:

startActivity(new Intent(android.provider.Settings.ACTION_DATE_SETTINGS));

What I would like to know is:

  1. Is it possible to link directly to the set time option?
  2. Is it possible to check that the user set the time correctly? I am aware of the TIME_CHANGED broadcast message, but I can't find any documentation on it

Update:

The TIME_CHANGED broadcast message doesn't provide any information about how it changed. This isn't explicitly documented, but I tried getData and getExtras and received no information. Additionally, looking at the rest of the documentation it appears that no data or extras are passed unless explicitly documented. Similarly, it is actually documented the ACTION_DATE_SETTINGS takes no input and it is implicit that it takes no extras, so there is no way to control it more precisely.

CommonsWare pointed out what should have been obvious to me - that simply checking that the user set the time to the value retrieved from the server, without worrying about the time spent in the options menu, will almost always work. As this assumption could actually be false, if I were using this method, then I would ensure the message said that the time was probably set correctly or incorrectly, rather than using a definite statement.

However, I discovered elapsedRealtime and so I will actually implement this detection properly.

like image 438
Casebash Avatar asked Feb 27 '23 01:02

Casebash


1 Answers

Is it possible to link directly to the set time option?

Try:

startActivity(new Intent(android.provider.Settings.ACTION_DATE_SETTINGS));

Is it possible to check that the user set the time correctly?

:: shrug ::

After the application gets control again, examine the time.

like image 70
CommonsWare Avatar answered Mar 08 '23 10:03

CommonsWare