I have this intent for let user choose images:
fun launchChooseFileIntent(callerFragment: BaseFragment, REQUEST_CODE: Int) {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "image/*,"
}
startActivityForResult(intent, REQUEST_CODE)
}
Now i need that user can choose both images and pdf documents. I've try to change type string like
type = "image/*,application/pdf"
or like
type = "image/*|application/pdf"
but it doesn't work.
I've try also to add extra to intent like
putExtra(Intent.EXTRA_MIME_TYPES, arrayOf("image/*", "application/pdf"))
but the app crash.
How can i solve it?
Answer on your question is here
Here is my sample code, tested in api 28.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
String[] mimeTypes = {"application/pdf", "text/csv", "text/plain"};
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
startActivityForResult(Intent.createChooser(intent, dialogTitle), requestCode);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With