[英]Delete last(recent) image from gallery from internal memory
I want to delete image from gallery that was most recently captured. 我想从图库中删除最近捕获的图像。 I have followed a couple of SO questions, but nothing seems to work.
我遵循了几个SO问题,但似乎没有任何效果。 Can anyone give me a simple code that works?
谁能给我一个简单的有效代码?
Sample code: 样例代码:
public void deleteImage() {
File f = new File("/storage/emulated/0/Pictures");
File [] files = f.listFiles();
Arrays.sort(files, new Comparator<File>() {
@Override
public int compare(File a, File b) {
if (a.lastModified() < b.lastModified())
return 1;
if (a.lastModified() > b.lastModified())
return -1;
return 0;
}
});
files[0].delete();
}
This code sorts the files in gallery folder by time of last modification, and delete the most recent file. 此代码按上次修改时间对Gallery文件夹中的文件进行排序,并删除最新文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.