0

How can I select multiple images from gallery by using java. I have Use this code but no error occurs and can not able to select image from gallery. Here is my code:

mainactivity.java

 //button On Click:
{

    Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
    final int ACTIVITY_SELECT_IMAGE = 1234;
    startActivityForResult(i, ACTIVITY_SELECT_IMAGE); 

    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data){
                     //super.onActivityResult(requestCode,resultCode,data);

    switch(requestCode) { 
                        case 1234:
                            if(resultCode == RESULT_OK){  
                                Uri selectedImage = data.getData();
                                String[] filePathColumn = {MediaStore.Images.Media.DATA};

                                Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
                                cursor.moveToFirst();

                                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                                String filePath = cursor.getString(columnIndex);
                                cursor.close();


                                Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
                                /* Now you have choosen image in Bitmap format in object "yourSelectedImage". You can use it in way you want! */
                            }
                        }
            }

            });

It's not working. I can't select image.

salih kallai
  • 879
  • 2
  • 13
  • 34
Drashti
  • 111
  • 2
  • 12

2 Answers2

0

@Drashti Kapadia :You can use Android open source library MultipleImagePick. And it uses Universal image loader library for asynchronous loading and caching.

Features and Benefits:

  1. Select multiple images - Option to select multiple images from Gallery and fast scroll over the Gallery
  2. Maximum selection limit - Option to set maximum image selection limit
  3. Custom button title and error message - There is a option to customize button title and error message
  4. Method for scale down the bitmap - To avoid out of memory issue, this module has in build bitmap scale down method
  5. Callback methods - Success, error and cancel callback methods
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

Try the following code. Hope this helps!

        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("image/*");
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); // allow the user to select multiple items, only available in Android API 18 and higher.
        startActivityForResult(intent, requestCode);
BNK
  • 23,994
  • 8
  • 77
  • 87