Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Display Images From Specific Folder in Gallery View

I'm trying to make a little app that displays only images from a specific folder in a gallery view. I have found a few examples, but every single one just ends up displaying only 1 image. This example I will post below was a WONDERFUL help, it does almost exactly what I want it to do, I just need to change it to display images from the specific folder, and not all folders. I've given this a few days worth of attempts, but I just don't seem to be adding in the right code. I feel like its a very simple thing that I am missing too. Any help would be greatly appreciated!

public class AndroidCustomGallery extends Activity {

    private int count;
    private Bitmap[] thumbnails;
    private boolean[] thumbnailsselection;
    private String[] arrPath;
    private ImageAdapter imageAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

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

                final String orderBy = MediaStore.Images.Media._ID;

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




                int image_column_index = imagecursor.getColumnIndex(MediaStore.Images.Media._ID);          
                this.count = imagecursor.getCount();        
                this.thumbnails = new Bitmap[this.count];       
                this.arrPath = new String[this.count];  
                this.thumbnailsselection = new boolean[this.count];

                for (int i = 0; i < this.count; i++) {

                    imagecursor.moveToPosition(i);

                    int id = imagecursor.getInt(image_column_index);        
                    int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA); 

                  thumbnails[i] = MediaStore.Images.Thumbnails.getThumbnail(        
                            getApplicationContext().getContentResolver(), id,       
                            MediaStore.Images.Thumbnails.MICRO_KIND, null);     

                    arrPath[i]= imagecursor.getString(dataColumnIndex);

                }

                GridView imagegrid = (GridView) findViewById(R.id.PhoneImageGrid);      
                imageAdapter = new ImageAdapter();      
                imagegrid.setAdapter(imageAdapter);     
                imagecursor.close();
like image 676
BossWalrus Avatar asked Jan 07 '13 16:01

BossWalrus


1 Answers

Figured it out! Below is the pasted code for anyone who wants to do something similar.

Cursor imagecursor = getContentResolver().query( MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        columns, 
                        MediaStore.Images.Media.DATA + " like ? ",
                        new String[] {"%/yourfoldername/%"},  
                        null);
like image 53
BossWalrus Avatar answered Sep 18 '22 03:09

BossWalrus