Multiple Mime Types in Android

How can I setup an android intent for multiple types of files (pdf, office, images, text) and return a path?

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 here.

How can i ask for multpile MIME types with ActivityResultLauncher.GetContent()?

is there any way to ask for multiple MIME types when using registerForActivityResult ?

Not directly with the current version of ActivityResultContracts.GetContent. However, you should be able to subclass it, override createIntent(), and from there customize the generated Intent. You can then try adding EXTRA_MIME_TYPES to that Intent with a String[] of the additional MIME types that you want.

How to add multiple Mime types for volley MultipartEntityBuilder

use mime type "*/*" it will accept all types of files

var fileBody = ProgressRequestBody(fileToUpload, "*/*", this)

photos = MultipartBody.Part.createFormData(key, fileToUpload.name, fileBody)

Like in retrofit I make RequestBody object as above and it accepts any type of file



Related Topics



Leave a reply



Submit