1

I want to start in built gallery activity for multiple selection.

I have tried this, but it selects only one image.

Thanks in advance..!

Community
  • 1
  • 1
Noby
  • 6,562
  • 9
  • 40
  • 63

2 Answers2

1

You have to create your own list of images having checkboxes to select multiple image files.

Use the below code to get the cursor for gallery and create a list adapter which will iterate over cursor and will give image. This image can be used to show in list view with checkboxes.

String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null); 
Ravi Sharma
  • 873
  • 7
  • 24
  • For this you need to get the images URI and then create an adapter for the cursor of that URI and create a list view of images. Please refere to this : http://coderzheaven.com/2011/03/select-an-image-from-gallery-in-android-and-show-it-in-an-imageview/ – Ravi Sharma Oct 21 '11 at 14:26
  • in that we are opening the gallery for selection, and only one at a time. – Noby Oct 21 '11 at 15:16
  • but i don't want to open gallery for single selection. is there any way with out starting activity, we should get all the images. – Noby Oct 21 '11 at 15:17
  • No man this is for a custom list of images from which you can select multiple images by using checkboxes. Just google around and you will find how to create a list of images. – Ravi Sharma Oct 22 '11 at 06:29
0

Download source code from here (Get all images from gallery in android programmatically)

public ArrayList<Model_images> fn_imagespath() {
        al_images.clear();

        int int_position = 0;
        Uri uri;
        Cursor cursor;
        int column_index_data, column_index_folder_name;

        String absolutePathOfImage = null;
        uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

        String[] projection = {MediaStore.MediaColumns.DATA, MediaStore.Images.Media.BUCKET_DISPLAY_NAME};

        final String orderBy = MediaStore.Images.Media.DATE_TAKEN;
        cursor = getApplicationContext().getContentResolver().query(uri, projection, null, null, orderBy + " DESC");

        column_index_data = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
        column_index_folder_name = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
        while (cursor.moveToNext()) {
            absolutePathOfImage = cursor.getString(column_index_data);
            Log.e("Column", absolutePathOfImage);
            Log.e("Folder", cursor.getString(column_index_folder_name));

            for (int i = 0; i < al_images.size(); i++) {
                if (al_images.get(i).getStr_folder().equals(cursor.getString(column_index_folder_name))) {
                    boolean_folder = true;
                    int_position = i;
                    break;
                } else {
                    boolean_folder = false;
                }
            }


            if (boolean_folder) {

                ArrayList<String> al_path = new ArrayList<>();
                al_path.addAll(al_images.get(int_position).getAl_imagepath());
                al_path.add(absolutePathOfImage);
                al_images.get(int_position).setAl_imagepath(al_path);

            } else {
                ArrayList<String> al_path = new ArrayList<>();
                al_path.add(absolutePathOfImage);
                Model_images obj_model = new Model_images();
                obj_model.setStr_folder(cursor.getString(column_index_folder_name));
                obj_model.setAl_imagepath(al_path);

                al_images.add(obj_model);


            }


        }


        for (int i = 0; i < al_images.size(); i++) {
            Log.e("FOLDER", al_images.get(i).getStr_folder());
            for (int j = 0; j < al_images.get(i).getAl_imagepath().size(); j++) {
                Log.e("FILE", al_images.get(i).getAl_imagepath().get(j));
            }
        }
        obj_adapter = new Adapter_PhotosFolder(getApplicationContext(),al_images);
        gv_folder.setAdapter(obj_adapter);
        return al_images;
    }

Thanks!

Deepshikha Puri
  • 2,104
  • 22
  • 23