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

后端 未结 3 978
清酒与你
清酒与你 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:34

    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.

提交回复
热议问题