how to make intent.setType for pdf,xlsx and txt file android?

前端 未结 7 2077
情话喂你
情话喂你 2020-12-04 21:48

I want to choose only pdf, xlsx and txt file from storage but intent.setType can do only one file(eg.txt file only (or) pdf file only). Is it possible to get all three files

7条回答
  •  醉梦人生
    2020-12-04 22:39

    You can use Intent.ACTION_OPEN_DOCUMENT,

    Each document is represented as a content:// URI backed by a DocumentsProvider, which can be opened as a stream with openFileDescriptor(Uri, String), or queried for DocumentsContract.Document metadata.

    All selected documents are returned to the calling application with persistable read and write permission grants. If you want to maintain access to the documents across device reboots, you need to explicitly take the persistable permissions using takePersistableUriPermission(Uri, int).

    Callers must indicate the acceptable document MIME types through setType(String). For example, to select photos, use image/*. If multiple disjoint MIME types are acceptable, define them in EXTRA_MIME_TYPES and setType(String) to */*.

    For the more details, please refer this link

    http://developer.android.com/reference/android/content/Intent.html#ACTION_OPEN_DOCUMENT

    Note that this is only available on API Level 19+.

提交回复
热议问题