Android-我如何获得由系统保存最新的文件的URI? [英] Android- How do i get the URI of the latest file saved by the system?

查看:302
本文介绍了Android-我如何获得由系统保存最新的文件的URI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android的,我怎么可能得到保存到系统中的URI最后一个文件?我需要这种能力对于图像编辑工作的应用程序。至于我可以告诉ContentObserver只能检查,如果事情已经改变既不MediaStore.Images.Media或MediaStore.Files有我可以使用的方法。任何帮助将大大AP preciated。

In android, how could I get the URI last file saved to the system? I need this ability for an image editting application. As far as I can tell ContentObserver can only check if something has changed and neither MediaStore.Images.Media or MediaStore.Files have a method I could use. Any help would be greatly appreciated.

推荐答案

您可以循环槽您的应用程序是针对文件夹(S)中的文件并获得最新的文件线槽上次更改时间()方法,那么你可以得到它的位置与的getPath()方法。

You could iterate trough the files in the folder(s) your application is targeting and get the newest file trough the lastModified() method then you could get it's location with the getPath() method.

public File getNewestFileInDirectory() {
   File newestFile = null;

   // start loop trough files in directory
   File file = new File(filePath);
   if (newestFile == null || file.lastModified().after(newestFile.lastModified())) {
      newestFile = file;
   }
   // end loop trough files in directory

   return newestFile;
}

这篇关于Android-我如何获得由系统保存最新的文件的URI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆