Is there a way to detect when the user has changed the clock time on their device?

前端 未结 5 1119

Is there a way to detect when the Android system clock has been reset by the user in Android?

I\'m designing an app which uses system time to determ

5条回答
  •  萌比男神i
    2020-11-27 03:11

    The system time (System.currentTimeMillis()) would change if the user adjusted the clock, but the elapsed time since boot (SystemClock.elapsedRealtime()) hopefully would not. By tracking the differential between these two, it would be possible to detect major changes to the system clock by the user.

    It would be important not to track small changes that might be caused by the network updating the system clock. I'm going to assume that for my purposes, any change under about a half hour is irrelevant; the system time shouldn't change on the Locale country changing but that might be worth eliminating also.

    The elapsed realtime would obviously reset on boot so I should include a BroadcastReceiver to reset the differential on receiving android.intent.action.BOOT_COMPLETED.

提交回复
热议问题