簡體   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