Q:

How to get Last Access Time of any file in Android Without Using BasicFileAttribute Class

I want a class which would be a part of an Android application that can directly provide me the last open status or last access status of any file like images, videos. The BasicFileAttribute.class seems not to work for me. The solution need to use JDK 8. I don't want to use JDK 7.

A:

You can use Os.stat - since api 21, it returns StructStat which contains field st_atime with Time of last access (in seconds). example:
if (Build.VERSION.SDK_INT >= 21) {
   try {
      StructStat stat = Os.stat("/path/to/my/file");
      if (stat.st_atime != 0) {
           // stat.st_atime contains last access time, seconds since epoch
      }
   } catch (Exception e) {
      // deal with exception
   }
}

Other solution is to execute shell command stat :
Process p = Runtime.getRuntime().exec("stat -c \"%X\" /path/to/file");
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(
  p.getInputStream()));
String line = reader.readLine();
long time_sec = 0;
if (!TextUtils.isEmpty())
 time_sec = Long.parseLong(line);

I have not tested above code - but it looks like it should work.
Third aproach would be to use NDK and call stat function from C or C++.

