Get images of a specific folder on Android

In my application, I have created GridView

to display an image from a specific folder. The problem is I want to get images from the DCIM / 100ANDRO folder. What type of arguments should be passed through the request to get this type of images? Please provide me with a solution.

I am using the following code to extract which gives me images captured by camera

        //importing only camera images and storing in ArrayList of class Images     type
        String[] projection = {
        MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
        MediaStore.Images.Media.DISPLAY_NAME
        };
        String selection = MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " = ?";
        String[] selectionArgs = new String[] {
            "Camera"
        };

        Cursor mImageCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, selection, selectionArgs, null ); 

        if (mImageCursor != null)
        {

            mImageCursor.moveToFirst();

            for (int i = 0; i < mImageCursor.getCount(); i++)
            {
                Images im=new Images();
                eachImageView=new ImageView(this);
                int imageId = mImageCursor.getInt((mImageCursor.getColumnIndex( MediaStore.Images.Media._ID)));
                Bitmap bm = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), 
                    imageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
                im.setBitmap(bm);
                eachImageView.setImageBitmap(bm);
                im.setImageView(eachImageView);

                arrayOfImages.add(im);

                mImageCursor.moveToNext();
            }
        }

      

The offer will be appreciated!

+3


source to share


5 answers


File folder = new File(Environment.getExternalStorageDirectory().toString() + "/Folder Name/");
folder.mkdirs();
File[] allFiles = folder.listFiles(new FilenameFilter() {
    public boolean accept(File dir, String name) {
        return (name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".png"));
    }
});

      



+4


source


First give the path you are accessing and then use Bitmap.DecodePath (path) to load the bitmap. Try it.



File path = new File(Environment.getExternalStorageDirectory(),"DCIM/100ANDRO");
if(path.exists())
{
    String[] fileNames = path.list();
}
for(int i = 0; i < filename.length; i++)
{
     Bitmap mBitmap = Bitmap.decodeFile(path.getPath()+"/"+ fileNames[i]);
     ///Now set this bitmap on imageview
} 

      

+3


source


After checking this

 File sdcardPath = new File(Environment.getExternalStorageDirectory()
    .getPath() + "/100ANDRO"); 
   Log.v(sdcardPath.getPath());

      

Check that the path is correct. If sdcardPath is not null then try following logic

int imageCount = sdcardPath.listFiles().length;
  for (int count = 0; count < imageCount - 1; count++) {
   ImageView eachImageView= new ImageView(this);
   Bitmap bmp = BitmapFactory.decodeFile(sdcardPath.listFiles()[count].getAbsolutePath());
   eachImageView.setImageBitmap(bmp);

      

+1


source


If you understand correctly, you want your GridView images to appear in a specific folder on the device.

In your request, use the following the Uri: MediaStore.Images.Media.EXTERNAL_CONTENT_URI

. This will allow images to be searched all over the "primary" external memory. If you want to search only in a specific folder - use a specific Uri.

You can create an object File

with an outline of your location and then create a Uri from that file. For example:

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

      

Then in your request for images, you can use this Uri. That is, you will have:

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

      

Then you can still handle the returned cursor in the same way as the data format. However, the returned data will only contain images from the requested folder.

Hope it helps :)

0


source


I extracted the path to the images from a specific folder and displayed it in the view of the recycling program. The code is in Kotlin, but you can get an idea of ​​it.

var fileNames :List<String> ?=null
    val path = File(getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).path,"Folder Name")
    if (path.exists()) {
         fileNames = path.list().toList()
    }

      

So, you now have a list of image paths that can be passed to the processor view using the processor view adapter. Easy :-)

0


source







All Articles