I need an Intent to pick a video with a specific format

1.7k views Asked by At

I need to pick photo or video from the gallery.

But need to restrict video format for example only for mp4 and mov or other specific later.

Can I achieve it with adding some options to this kind of code?

            Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            i.addCategory(Intent.CATEGORY_OPENABLE);
            i.setType("*/*");
            i.putExtra(Intent.EXTRA_MIME_TYPES, new String[]{"image/*", "video/*"});
            startActivityForResult(i, requestCode);
1

There are 1 answers

6
Onur D. On BEST ANSWER

Instead of video/* you should narrow it down to video/mp4 or video/quicktime or both. Putting * basically means all video formats.

An example:

Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
i.putExtra(Intent.EXTRA_MIME_TYPES, new String[]{"image/jpeg", "image/png", "video/mp4", "video/quicktime"});
startActivityForResult(i, requestCode);