0

My app is working well for users submitting their jobs e.g. check in/out job. The problem is end users can physically alter their device time and provide false check in and out times.

However the time from the internet doesn't work in the sense that users are not always online therefore am looking for alternative times that I can use

last_Check_in.check_out = System.currentTimeMillis();
// this can easily be manipulated if a user changes time in settings

I expect a time e.g. gps time which works offline and can't be manipulated.

Rumit Patel
  • 8,830
  • 18
  • 51
  • 70
Watson
  • 1
  • 1
  • 2
  • What about `LocalDateTime.now()`? It is from `java.time.LocalDateTime`... – deHaar Feb 08 '19 at 12:21
  • obtains the current date-time from the system clock therefore if i push forward or backwards my system time it will still give me manipulated time – Watson Feb 08 '19 at 12:26
  • You could check out this post about preventing time manipulation: https://stackoverflow.com/questions/13716546/preventing-timer-manipulation-from-end-user-with-android-timertask-and-timer – tijn167 Feb 08 '19 at 12:30
  • thanks for response but not much from that link @tijn167 – Watson Feb 08 '19 at 13:44

1 Answers1

0

Generally this is not possible. The user can always set the device (system) clock leaving you with no clue when offline.

However, the combination of two means may help you in many situations.

  1. Current time from some server, either your own server or just some server somewhere on the internet.
  2. Time since the device was booted.

Use your search engine to find out how to get each of the two. If at one point the device is online, you can get both approximately simultaneously. From them you know the correspondence between them. You may for example calculate the real point in time the device was booted and store this. Then at some later point when the device is offline, you can still get the time since the device was booted and from this calculate the real time independently of the system clock.

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
  • 1
    time since last boot is always good but doesnt work if the device has been off for a while – Watson Feb 08 '19 at 13:43