Retrieve images of particular folder in Android

后端 未结 4 1400
一个人的身影
一个人的身影 2020-12-17 03:40

In my application I created the GridView to show the image from particular folder. The issue is that I want to retrieve images from the DCIM/100ANDRO folder. Wh

4条回答
  •  一整个雨季
    2020-12-17 04:08

    If I understand you correctly, you wish to have your GridView show images from a certain folder on the device.

    In your query, you use the following Uri: MediaStore.Images.Media.EXTERNAL_CONTENT_URI. This will search for images everywhere on the "primary" external storage. If you only want to search in a specific folder - use a specific Uri.

    You can create a File object with the path of your location, then create a Uri from that File. For example:

    File myFile = new File("/scard/myfolder");
    Uri myUri = Uri.fromFile(myFile);
    

    Then in your query for images, you can use this Uri instead. That is to say you would have:

    Cursor mImageCursor = getContentResolver().query(myUri, projection, selection, selectionArgs, null );
    

    Then you could still handle the returned cursor in the same way, as the format of data is the same. However, the returned data would only contain images from your desired folder.

    Hope this helps :)

提交回复
热议问题