2

I am trying to achieve lastAccessedTime of a File in Android, for which I tried the following 2 methods:

  1. Using lstat as described of its use here.

But Android does not use lastAccessedTime, during which either lastModified/fileCreation time is returned.

  1. Using file.setLastModified, but Android is returning false on performing setLastModified over a file.

    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 ?

  1. 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.

Community
  • 1
  • 1
jay
  • 1,982
  • 2
  • 24
  • 54

0 Answers0