Making the user change the time in Android

13,298

Solution 1

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.

Solution 2

In case someone wants to open from ADB

adb shell am start -a android.settings.DATE_SETTINGS
Share:
13,298
Casebash
Author by

Casebash

Bachelor of Science (Adv Maths) with Honors in Computer Science from University of Sydney Programming C/C++/Java/Python/Objective C/C#/Javascript/PHP

Updated on June 27, 2022

Comments

  • Casebash
    Casebash almost 2 years

    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.