Is there any additional information available from Intent.ACTION_TIME_CHANGED? There\'s nothing in getData() or getExtras().
I would like to know:
T
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.
Happy coding.
I looked into source code of Android and this broadcast doesn't have any extras. So, there is no way to learn this info.
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");
}
}