I am trying to achieve lastAccessedTime of a File in Android, for which I tried the following 2 methods:
- Using
lstat
as described of its use here.
But Android does not use lastAccessedTime, during which either lastModified/fileCreation time is returned.
Using
file.setLastModified
, but Android is returning false on performingsetLastModified
over afile
.long now = new Date().getTime() boolean success = file.setLastModified(now)
Few threads in stackoverflow described this bug with Android, but all of them are quite old. Did Android resolve this known issue in later versions ? or is there and other solution for fetching lastAccessedTime of a file ?
The ugly fix as described here.
RandomAccessFile raf = new RandomAccessFile(file, "rw"); long length = raf.length(); raf.setLength(length + 1); raf.setLength(length); raf.close();
I'm afraid if this would corrupt any of the files.
Would be grateful for any help.