4

Is there any additional information available from Intent.ACTION_TIME_CHANGED? There's nothing in getData() or getExtras().

I would like to know:

  • The time phone had before setting new time;

  • Who has changed the time: the user (manually) or the phone carrier?

Any other way to get those informations are welcome!

Christian
  • 7,062
  • 9
  • 53
  • 79

3 Answers3

3

I looked into source code of Android and this broadcast doesn't have any extras. So, there is no way to learn this info.

Victor Ronin
  • 22,758
  • 18
  • 92
  • 184
  • Thank you for researching this. I just wanted to comment that this deminishes the usability of the broadcast severely! I am sending timestamps for user actions (delivery state of cargo) using gps. I also record offset of system time to gps time. Sadly I regularly get hefty wrong jumps when gps signal is gone/too bad. And the only thing I can do is assuming that the system time is exactly gps time (both taken as utc) when this broadcast comes in. I assume it will show to go wrong also. – FrankKrumnow Aug 20 '19 at 13:15
1

You can do one thing if the accuracy of previous time is not that important. You can get the previous time with +/- 1 minute accurate by following way..

Register for broadcast action ACTION_TIME_TICK (This will be broadcasted every minute).

When ever the time ticks, if there is a difference of more than 1 minute between your current time and last tick time, you can infer that there occured a time change. After that you just update the new time to shared preference. Thats all.

  1. Register for ACTION_TIME_TICK broadcast.
  2. When broadcast received : 2.1 If first time broadcast, Enter the current system time to Shared Preference. 2.2 else compare the current time with previously entered time and if occurs a difference of more than 1 minute, means the time time has changed. Then update the new system time to SP.

Happy coding.

Eldhose M Babu
  • 14,382
  • 8
  • 39
  • 44
  • I often use system utc timestamps to remember what was done when so I do not have to use timers everywhere but can check the age of certain evaluations when needed. I will try to use this idea without saving to disk while my gps service is running. When service is killed you could miss some ACTION_TIME_CHANGED so when restarting you would compute the difference of time wrongly. While the service is alive I will try to use this idea. It may help with any "timers" that don't need more than 1 min precision and don't run longer than my service typically runs (8h). Thank you – FrankKrumnow Aug 20 '19 at 13:38
0

I don't think getting the why the time changed is possible, though finding out the amount the time was changed should be possible by comparing System.currentTimeMillis() to the SystemClock.elapsedRealtime(), since SystemClock.elapsedRealtime() does not get adjusted in this case.

An example would be something like:

private long realtimeOffset = System.currentTimeMillis() - SystemClock.elapsedRealtime();
private void onReceive(Context context, Intent intent) {
    if(Intent.ACTION_TIME_CHANGED.equals(intent.getAction()) {
        long prevRealtimeOffset = realtimeOffset;
        realtimeOffset = System.currentTimeMillis() - SystemClock.elapsedRealtime();
        Log.i(TAG, "Clock was adjusted by: " + (realtimeOffset - prevRealtimeOffset) + " ms");
    }
}
breenger
  • 649
  • 4
  • 6