Android上文件上次访问时间

Android上文件上次访问时间,android,lastaccesstime,Android,Lastaccesstime,有没有办法在Android中获取文件的最新访问时间。我知道如何使用javanio.file包实现这一点,但是,Android对Java7的支持非常有限,并且不包括该文件包。我对lastModified不感兴趣,只对LastAccess感兴趣,因为我想删除最旧的读取文件 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { StructStat stat =

有没有办法在Android中获取文件的最新访问时间。我知道如何使用javanio.file包实现这一点,但是,Android对Java7的支持非常有限,并且不包括该文件包。我对lastModified不感兴趣,只对LastAccess感兴趣,因为我想删除最旧的读取文件

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            StructStat stat = null;
            try {
                stat = Os.stat("/sdcard/Pictures/abc.jpg"); // File path here
            } catch (ErrnoException e) {
                e.printStackTrace();
            }
          long  t2 = stat.st_atime *1000L;
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(t2);

            SimpleDateFormat formatter =  new SimpleDateFormat("dd-MM-yyyy hh-MM-ss");
            String formattedDate = formatter.format(calendar.getTime());}
这只适用于上面的棒棒糖API


还请注意,st_atime返回的时间以秒为单位,而不是以毫秒为单位。

如果没有其他方法,您可以在stat()周围编写一个小型NDK包装器,但是内核只能在其所在的文件系统实际跟踪时提供此信息,这可能是也可能不是。谢谢,但是我相信stat命令在Android上是不可用的,它可能不可用,但我说的不是stat命令,而是stat()系统调用,它绝对是可用的。例如,请参见linuxmanpages.com/man2/stat.2.php,尽管Android的仿生libc在
中定义了不同的结构,使用了64位类型,并且显然实际使用了内核的stat64()。@ChrisStratton是否可以通过Java,使用Runtime.getRuntime().exec(…)来实现?是否可以使用root?@ChrisStratton-您是否能够在android中获取文件的上次访问时间?