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

和自甴很熟 提交于 2019-11-30 17:59:13

问题


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!


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/7756493/android-is-there-any-additional-information-from-intent-action-time-changed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!