Android: is there any additional information from Intent.ACTION_TIME_CHANGED?

后端 未结 3 973
清酒与你
清酒与你 2021-01-06 04:51

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

I would like to know:

  • T

3条回答
  •  既然无缘
    2021-01-06 05:38

    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");
        }
    }
    

提交回复
热议问题