3

How can I get list of all images on the phone and show all of them in a listview. Basically I have a dialog where I am asking for a album name and a photo name which will be populated with the selection made from the listview. How do I get the file URI using this code...

Android list all images available

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_IMAGE);
Community
  • 1
  • 1
jrdnsingh89
  • 215
  • 2
  • 7
  • 18

1 Answers1

3

In answer to another question, hpique answered that here:

public static List<String> getCameraImages(Context context) {
    final String[] projection = { MediaStore.Images.Media.DATA };
    final String selection = MediaStore.Images.Media.BUCKET_ID + " = ?";
    final String[] selectionArgs = { CAMERA_IMAGE_BUCKET_ID };
    final Cursor cursor = context.getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI, 
            projection, 
            selection, 
            selectionArgs, 
            null);
    ArrayList<String> result = new ArrayList<String>(cursor.getCount());
    if (cursor.moveToFirst()) {
        final int dataColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        do {
            final String data = cursor.getString(dataColumn);
            result.add(data);
        } while (cursor.moveToNext());
    }
    cursor.close();
    return result;
}
Community
  • 1
  • 1
HalR
  • 11,411
  • 5
  • 48
  • 80