Multiple MIME types in Android

James picture James · Nov 8, 2009 · Viewed 39.7k times · Source

Is there a way to use intent.setType() and supply multiple broad types (like images and video)?

I am using an ACTION_GET_CONTENT. It seems to be working with just comma-separated types.

Answer

Fred picture Fred · May 2, 2014

In Android 4.4 when using the Storage Access Framework you can use the EXTRA_MIME_TYPES to pass multiple mime types.

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