2

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);
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Kyryl Zotov
  • 1,788
  • 5
  • 24
  • 44

1 Answers1

3

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);
Onur D.
  • 515
  • 3
  • 11
  • 1
    Can I pick both mov and mp4 format? Because seems mov is not supported by android? – Kyryl Zotov Oct 08 '18 at 15:01
  • Yes, by default Android is not supported playing .mov formatted video but you can work around this by using a 3rd party player like https://github.com/Tubitv/TubiPlayer or https://github.com/google/ExoPlayer. For picking .mov formatted video, I'm not sure if it'll work. Maybe you can try it and let us know from here :) – Onur D. Oct 08 '18 at 15:05
  • I can play it. The question is to pick it, and seems with this parameters mov is not pickable in android – Kyryl Zotov Oct 08 '18 at 15:11
  • https://github.com/nbsp-team/MaterialFilePicker I think you can give this a try. As far as I understand, this library uses regex to pick custom extensions. (You can write your own regex for .mov extension) – Onur D. Oct 08 '18 at 15:21
  • 1
    Actually yes, quicktime is the same as mov. But android handles only quicktime keyword! – Kyryl Zotov Oct 08 '18 at 15:36
  • Glad to hear it helped! – Onur D. Oct 08 '18 at 15:37