如何列出SD卡上的图像按照时间排序 [英] how to list images on sd card sorted according to time
本文介绍了如何列出SD卡上的图像按照时间排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用fololowing`得到SD卡的图像列表
但这些都没有排序
我如何才能让他们进行排序按名称或时间
在此先感谢
字符串ExternalStorageDirectoryPath =环境
.getExternalStorageDirectory()getAbsolutePath()。 字符串TARGETPATH = ExternalStorageDirectoryPath +/ somedirectoryname /; 文件targetdirectory中=新的文件(TARGETPATH); 文件[] =文件targetDirectory.listFiles();`
对于(文件文件:文件下载1){
list.add(file.getAbsolutePath()的toString());
}
解决方案
也许如果你使用它会更容易内置的内容提供商
MediaStore.Images.Media.query(CR,URI,投影,其中,排序依据)
是这样的:
的String [] =投影{MediaColumns._ID,MediaColumns.DISPLAY_NAME,MediaColumns.DATE_ADDED};
光标C = MediaStore.Images.Media.query(getContentResolver(),MediaStore.Images.Media.EXTERNAL_CONTENT_URI,投影,空,MediaColumns.DATE_ADDED);
然后就可以循环光标到你需要的任何。
I can get the list of images in sd card using fololowing`
but these are not sorted
how can I get them sorted either by name or time
thanks in advance
String ExternalStorageDirectoryPath = Environment
.getExternalStorageDirectory().getAbsolutePath();
String targetPath = ExternalStorageDirectoryPath + "/somedirectoryname/";
File targetDirectory = new File(targetPath);
File[] files = targetDirectory.listFiles();`
for (File file : files1) {
list.add(file.getAbsolutePath().toString());
}
解决方案
Maybe it will be easier if you use the built-in content provider
MediaStore.Images.Media.query(cr, uri, projection, where, orderBy)
something like this:
String[] projection = {MediaColumns._ID, MediaColumns.DISPLAY_NAME, MediaColumns.DATE_ADDED};
Cursor c = MediaStore.Images.Media.query(getContentResolver(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, MediaColumns.DATE_ADDED);
then you can loop the cursor to do whatever you need.
这篇关于如何列出SD卡上的图像按照时间排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文