简体   繁体   English

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

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

I want to load all the Images present in the users device. 我要加载用户设备中存在的所有图像。 I know that Images can be loaded using Media Store but the biggest drawback for me is that the Images which are present in the folder having .nomedia file are not loaded/retrieved using Media Store. 我知道可以使用Media Store加载图像,但是对我来说最大的缺点是使用Media Store无法加载/检索具有.nomedia文件的文件夹中的图像。

Is there an efficient way using Media Store or without using Media Store to load all the Images present in Android device irrespective of their parent folder having a .nomedia file? 是否有一种有效的方式使用Media Store或不使用Media Store加载Android设备中存在的所有图像,而不管其父文件夹是否具有.nomedia文件?

This is how I am loading Images whose parent directory does not have .nomedia file: 这就是我加载其父目录没有.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
            }
        }

    }

I know that I can scan each and every folder and check if there is a Image present in it but it would consume a lot of time. 我知道我可以扫描每个文件夹并检查其中是否有图像,但这会花费很多时间。

The MediaStrore does not scan directories which contain a .nomedia file. MediaStrore不扫描包含.nomedia文件的目录。

So you cannot ask the MediaStore to deliver them. 因此,您不能要求MediaStore交付它们。

You indeed have to make your own media store. 您确实必须建立自己的媒体商店。

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

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