繁体   English   中英

如何使用Media Store加载所有图像?

[英]How to load all the Images using Media Store?

我要加载用户设备中存在的所有图像。 我知道可以使用Media Store加载图像,但是对我来说最大的缺点是使用Media Store无法加载/检索具有.nomedia文件的文件夹中的图像。

是否有一种有效的方式使用Media Store或不使用Media Store加载Android设备中存在的所有图像,而不管其父文件夹是否具有.nomedia文件?

这就是我加载其父目录没有.nomedia文件的图像的方式:

public void getImages(Context context) {

        File Image_File;
        final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID};

        String orderBy = MediaStore.Images.Media.DATE_MODIFIED ;

        Cursor cursor = context.getContentResolver().query(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
                null, orderBy);

        if (cursor != null)
        {
            cursor.moveToFirst();
            final int dataColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);

            while (cursor.moveToNext()) {
                Image_File = new File(cursor.getString(dataColumnIndex));

               //Add the Image to the list
            }
        }

    }

我知道我可以扫描每个文件夹并检查其中是否有图像,但这会花费很多时间。

MediaStrore不扫描包含.nomedia文件的目录。

因此,您不能要求MediaStore交付它们。

您确实必须建立自己的媒体商店。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM