Reputation: 657
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.
Upvotes: 1
Views: 3152
Reputation: 4812
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;
}
Upvotes: 3