4

I am trying to allow a user to choose an image or video from his device, and currently it only shows video or image depending what is written first in the following code:

 Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

                //set type to include video too
                galleryIntent.setType("image/*, video/*");

                startActivityForResult(galleryIntent, GALLERY_IMAGE_REQUEST_CODE);
            }
        };

not sure what I am doing wrong, but setType seems right I tried with and without the comma in between image and video...

Lion789
  • 4,402
  • 12
  • 58
  • 96

3 Answers3

1

I ran into the same issue where it would only use the first MIME type in the list.

This ended up working for me:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("*/*");
String[] mimeTypes = {"image/*", "video/*"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
startActivityForResult(intent, REQUEST_CODE_CAMERA_ROLL);
Steve Strates
  • 433
  • 3
  • 13
0
 case 2: //Choose Pic

                            Intent choosePhotoIntent = new Intent(Intent.ACTION_GET_CONTENT);
                            choosePhotoIntent.setType("image/*");
                            startActivityForResult(choosePhotoIntent, PICK_PHOTO_REQUEST);
                            break;
                        case 3: //Choose Video
                            Intent chooseVideoIntent = new Intent(Intent.ACTION_GET_CONTENT);
                            chooseVideoIntent.setType("video/*");
                            Toast.makeText(MyActivity.this,getString(R.string.video_message), Toast.LENGTH_LONG).show();
                            startActivityForResult(chooseVideoIntent, PICK_VIDEO_REQUEST);
                            break;

Try above..you need to have separate options..

NitZRobotKoder
  • 1,046
  • 8
  • 44
  • 74
0

This works for me:

Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, PICK_MEDIA);
degemenc
  • 481
  • 4
  • 10