views:

363

answers:

1

Hi, am looking for a way to find images on the SD card, or at least images taken by the camera.

The ideal solution would be getting a collection of file paths or URIs for the images. I guessing you can do this through the MediaStore I just can't figure out how.

Thank you

+2  A: 

After looking at more MediaStore examples I came up with this and it gets the job done.

protected ArrayList<Uri> GetImageList(boolean getThumbs) 
{  
 ArrayList<Uri> images = new ArrayList<Uri>();
 String columnType;  
 Uri contentType;      
 String[] columnNames;

 if (getThumbs)
 {
   columnType = MediaStore.Images.Thumbnails._ID;
   contentType = MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI;
 }
 else
 {
  columnType = MediaStore.Images.Media._ID;
  contentType = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
 }

 columnNames = new String[]{columnType};    
 Cursor cursor = managedQuery(contentType, columnNames, null, null, null);   
 int columnIndex = cursor.getColumnIndexOrThrow(columnType);

 for(int i = 0; i < cursor.getCount(); i++)
 {
  cursor.moveToPosition(i);
  int id = cursor.getInt(columnIndex);
  images.add(Uri.withAppendedPath(contentType, "" + id));
 }

 return images;
}

It returns the Uri of all the images or the Uri of the thumbnail of all the images on the sdcard.

pegisys