I am creating an app which can monitor elapsed time taken for a particular task. The times are taken from server and its working fine. But when I added offline feature , I take time from System.currentTimeMillis();
. There is problem ,if user change their phone time ,then they can easily cheat the elapsed time. Is there any other way I can fetch duration of particular task interval.Or How can I prevent this cheating? I already search stack overflow for a good answer. but can't find anything. Please help
Asked
Active
Viewed 3,066 times
3

Vinayak B
- 4,430
- 4
- 28
- 58
2 Answers
3
You could start a thread to count the elapsed time yourself. Place counter inside a service, to prevent it closing with the app. If the service if closed by the device restarting or whatever, then it needs to go online to confirm the time again before continuing.
As long as the device is not restarted or the service being closed by system due to low resources, the user will be able to stay offline.

meeeee
- 2,929
- 3
- 22
- 25
-
1If the app close or phone switch off this won't work – Vinayak B Oct 03 '17 at 06:20
-
1This is the possible solution right now I am working. But the problem is I can't go to online when service restarted. that means I have to fetch System.currentTimeMillis(); . this is the problem. – Vinayak B Oct 03 '17 at 06:46
-
How about using SystemClock.elapsedRealtime() . it will return milliseconds since boot, including time spent in sleep. Still need to go online after a restart – meeeee Oct 03 '17 at 06:49
2
From what I have seen through my research you'll have to store the time, on a server would be better to prevent the user to change it by accessing your app's files.
I believe these two links can give you a lead on the idea.

Teasel
- 1,330
- 4
- 18
- 25
-
When I am using server time the app works fine . but in offline , I am storing start time. But when a task complete, I am calculating end time using system time. there people changing there device time. – Vinayak B Oct 03 '17 at 06:10
-
There is no way to prevent the user from changing the system's date. The only thing you could do in offline mode would be to store the date and time and the calculate the elapsed time but you'd still have your problem. – Teasel Oct 03 '17 at 06:14