Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening a specific file extension

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?

like image 319
CaptainNemo Avatar asked Sep 18 '25 21:09

CaptainNemo


1 Answers

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.

like image 167
CommonsWare Avatar answered Sep 21 '25 11:09

CommonsWare