Multiple MIME types in Android

AndroidAndroid IntentMime Types

Android Problem Overview


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.

Android Solutions


Solution 1 - Android

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);

Solution 2 - Android

Actually, multiple mime-types are supported. Have you even tried it???

For example: intent.setType("image/*,video/*") will display photos and videos...

For me it works. It should work for you too...

[EDIT]: This works partially, as not all the gallery apps choose to implement support for multiple mime types filters.

Solution 3 - Android

Sorry, this is not currently supported. You have two options:

(1) Use a MIME type of */* and accept that there may be some things the user can pick that you won't be able to handle (and have a decent recovery path for that); or

(2) Implement your own activity chooser, doing direct calls on the package manager to get the activities that can handle both MIME types for the intent, merging those lists, and displaying them to the user.

Also, setType() does not work with comma-separated types at all. It must be one and only one MIME type.

Solution 4 - Android

For me what worked best was:

intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);


You can add several mime types like this

intent.setType("image/*|application/pdf|audio/*");

But the intent chooser will only display applications that can handle images because it is the first in the mime type string.

However if you have a file manager installed (I tested with the CyanogenMod file manager) you can choose a file that is audio or pdf or an image.

If the audio mime type is the first one, like this:

intent.setType("audio/*|image/*|application/pdf");

The intent chooser will display only applications that handle audio.
Again using the file manager you can select an image or pdf or audio.

Solution 5 - Android

you can pass multiple mime types if you separate with |

Intent.setType("application/*|text/*");

Solution 6 - Android

for my work with semicolons.

Example:

intent.setType("image/*;video/*")

or

sIntent.putExtra("CONTENT_TYPE", "image/*;video/*"); 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJamesView Question on Stackoverflow
Solution 1 - AndroidFredView Answer on Stackoverflow
Solution 2 - AndroidbazyleView Answer on Stackoverflow
Solution 3 - AndroidhackbodView Answer on Stackoverflow
Solution 4 - AndroidRaimundoView Answer on Stackoverflow
Solution 5 - AndroidCifusView Answer on Stackoverflow
Solution 6 - AndroidjavierView Answer on Stackoverflow