I was wondering if I can start an Intent for viewing a directory with a File browser (if there's one installed on the device) so I can open a folder like this:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/MyFolder");
intent.setDataAndType(uri, "MIME TYPE FOR FOLDERS");
startActivity(intent);
Directories are not considered to have MIME types on Windows. On Android, the directories exposed by a document provider are of type "vnd. android. document/directory" while those exposed by other content providers are typically of the form "vnd.
A MIME type consists of two parts: a type and a subtype. Currently, there are ten registered types: application, audio, example, font, image, message, model, multipart, text, and video.
This is an ancient question but I noticed that the directory MimeType had not actually been specified properly in any of the answers. I found this in the Google code sample for SAF (Storage Access Framework) android-StorageProvider:
DocumentsContract.Document.MIME_TYPE_DIR
Which is this string:
vnd.android.document/directory
So for the initial question:
Uri uri = Uri.parse(getFilesDir().getPath());
int OPEN_REQUEST = 1337;
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setDataAndType(uri, DocumentsContract.Document.MIME_TYPE_DIR);
startActivityForResult(intent, OPEN_REQUEST);
But the Storage Access Framework will navigate through the directories for you. So you may only need to do this:
int OPEN_REQUEST = 1337;
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, OPEN_REQUEST);
AndExplorer has vendor mime types to use AndExplorer as a file chooser:
vnd.android.cursor.dir/lysesoft.andexplorer.director
vnd.android.cursor.dir/lysesoft.andexplorer.file
See AndExplorer's developper documentation for more information. I think other file explorers as similar features, but I didn't find their docs yet.
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