Multiple MIME types in Android

后端 未结 6 2041
走了就别回头了
走了就别回头了 2020-12-01 00:42

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

I am using an ACTION_GET_CONTENT.

6条回答
  •  天涯浪人
    2020-12-01 01:26

    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.

提交回复
热议问题