1

Pick image/video the path is not get from download folder

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setType("*/*");
startActivityForResult(Intent.createChooser(intent, "Select Document"), PICK_PDF_REQUEST);  
Valentino Ru
  • 4,964
  • 12
  • 43
  • 78
velvizhi
  • 11
  • 3

1 Answers1

0
    Intent pickPhotoIntent = new Intent();
    pickPhotoIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    pickPhotoIntent.setAction(Intent.ACTION_GET_CONTENT);
    pickPhotoIntent.setType("*/*");
    startActivityForResult(Intent.createChooser(pickPhotoIntent, "Select Picture"), PICK_IMAGE);

In OnActivityResult you have to put below code

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == PICK_IMAGE && resultCode == RESULT_OK && null != data) {
        String[] filePathColumn = {MediaStore.Images.Media.DATA};
        String[] filePathColumnVideo = {MediaStore.Video.Media.DATA};
        ArrayList<String> imagesEncodedList = new ArrayList<String>();
        String picturePath;

        if (data.getClipData() != null) {
            int count = data.getClipData().getItemCount(); //evaluate the count before the for loop --- otherwise, the count is evaluated every loop.
            Uri selectedMediaUri;
            for (int i = 0; i < count; i++) {
                selectedMediaUri = data.getClipData().getItemAt(i).getUri();
                if (selectedMediaUri.toString().contains("image")) {
                    Cursor cursor = getContentResolver().query(selectedMediaUri, filePathColumn, null, null, null);
                    cursor.moveToFirst();
                    int columnIndex = cursor.getColumnIndexOrThrow(filePathColumn[0]);
                    picturePath = cursor.getString(columnIndex);
                    imagesEncodedList.add(picturePath);
                    Log.e("Image Path Multiple", "Image " + i + " " + picturePath);
                    cursor.close();
                } else if (selectedMediaUri.toString().contains("video")) {
                    Cursor cursor = getContentResolver().query(selectedMediaUri, filePathColumnVideo, null, null, null);
                    cursor.moveToFirst();
                    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                    picturePath = cursor.getString(columnIndex);
                    imagesEncodedList.add(picturePath);
                    Log.e("Image Path Multiple", "Video " + i + " " + picturePath);
                }

            }
        }
    }


}

In Android Studio logcat, you can find image paths like

Image Path Multiple: Image 0 your selected image path

Image Path Multiple: Video 1 your selected Video path

Nensi Kasundra
  • 1,980
  • 6
  • 21
  • 34