2

I want to design app in which I can get the time before the user has changed to any new time. I am using

android.intent.action.TIME_SET

To know that user has changed time

eg. Suppose current time is 10.00 pm User changed it to 09.00 pm So can i get previous time that is 10.00 pm

Tushar
  • 1,122
  • 1
  • 13
  • 28
  • And your question is? – jfs May 24 '13 at 07:05
  • So can i get previous time that is 10.00 pm ? – Tushar May 24 '13 at 07:09
  • What is the problem that you are trying to solve? – jfs May 24 '13 at 07:11
  • My app is time dependent and I am blocking a app in let 9pm to 11pm but if user changed time to something else when it is 10pm thats why I want to know correct time. – Tushar May 24 '13 at 07:14
  • You want the app to execute between 10pm to 11pm? – jfs May 24 '13 at 07:15
  • Yes but if user changed time to 12 when the current time is 10 how can i avoid it – Tushar May 24 '13 at 07:18
  • Already answered here http://stackoverflow.com/a/6230951/718. – jfs May 24 '13 at 07:21
  • I think above link will let me know that user has changed the time but how can i know that what was the previous time from which he changed to newone – Tushar May 24 '13 at 07:36
  • Why do you need to that? Just check if the current time is within 10-11pm. – jfs May 24 '13 at 07:53
  • @jfs Imagine a scenario that I want to block user's some activity from 8 pm to 10pm, so when time reaches to 7.30pm he changes time to let say 2pm and now hi will use that activity for 3 hrs and again changes time back to whatever hi want so he will keep using activity in between 8pm to 10pm and every time how can I solve this problem . . . – Tushar May 24 '13 at 15:56
  • @Tushar: Did u find any solution for this problem yet? To get the previous time just before it was changed? – Guna Jan 08 '15 at 07:33

2 Answers2

2

Question was asked some time ago, but I have generally the same problem and cannot find reasonable (efficient) solution.

Just to recall, I want to know the time that was set before user changed time. For example, user changed time from 6:12 PM to 3:21 PM. To the best of my knowledge, there is no information about previous time in android.intent.action.TIME_SET. But when handling this intent I want to somehow know that the time was set to 3:21 PM when there actually was 6:12 PM.(let assume the same day).

According to accepted answer to this question:

android detect user modifying device clock time

If I want to handle situations when network is not available, I have to kind of append my own timer to my application, measure time on my own, and when handling

android.intent.action.TIME_SET

get old time from this built-in timer.

But it seems to me, that this is quite heavy solution and I reckon there must be simpler way to do this.

So the question is, what is the best (most efficient and the most simple) way to handle situation described above. Despite this problem seems to me very common, I couldn't find fair solution.

Community
  • 1
  • 1
kostek
  • 801
  • 2
  • 15
  • 32
-1

You could try to monitor the difference between System.currentTimeMillis() and SystemClock.elapsedRealtime(). The value of System.currentTimeMillis() would be affected by the change of system time whereas the value of SystemClock.elapsedRealtime() would not.

devconsole
  • 7,875
  • 1
  • 34
  • 42