It is quite incredible how I could not find a simple solution to this question.
I am using the following code to obtain a file URI in my app:
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, READ_REQUEST_CODE);
I would like the dialog that opens to show files with a specific file extension (*.orcsc) only
How can this be done?
It can't. Android does not use file extensions much, and there is little support for it. Moreover, ACTION_OPEN_DOCUMENT
is designed around content, not files, and there is no requirement for content in a cloud storage provider to have a filename.
You are welcome to constrain by MIME type, replacing */*
with something that would be of relevance. Otherwise, see if there is a file chooser library that better fits your needs.
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