I'm developing an android application and hit the problem with determining system first boot up time. I mean i need to measure how much time already passed from device first boot up.
I know about solution with listening for ACTION_BOOT_COMPLETED and save anything in SharedPreferences, but i need another solution, because this one does not work for some cases. Maybe there is any system property?
Use case (excerpt from discussion)
- The filename of each file I receive from server includes a timestamp
taken from
System.currentMillis()
- I compare those timestamps in order to determine, which file the most current one is.
- Now, the user changes system time a few months ahead.
- I am still able to determine the most current file downloaded after user changed system time.
- Now, the user changes time back to original setting.
- The file downloaded on step 4 always wins when comparing timestamps.
The silver bullet to solve this problem would be a timestamp that counts seconds since first boot (after factory reset). Just like SystemClock.elapsedRealtime()
but without reset after each boot. Unfortunately, the answers so far tell us, that this silver bullet doesn't exist.
However, many answers show a great variety of options how to tackle that problem. OneWorld123 commented each answer, how that suited his needs.
System.currentMillis()
) which behaves like a wall clock can't be a solution as well as file timestamps which are created with that very system clock. I need a timestamp that never gets changed. Almost like theSystemClock.elapsedRealtime()
, just since the first time the device came alive. – Gifferd/sdcard/Android/
is created by the Android system (On first boot I guess ?), so you could look at the timestamp on it or on the files in it or in other system-created directories to determine the time the date / time the device was first booted (as long as the clock was correct during the first boot). Unfortunately I have no idea if this works. – Zindman