Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MIME type for directories in Android

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);
like image 997
Pedriyoo Avatar asked Jan 20 '11 16:01

Pedriyoo


People also ask

What is the MIME type of a folder?

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.

What are the different MIME types?

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.


2 Answers

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);
like image 124
ByteSlinger Avatar answered Oct 12 '22 05:10

ByteSlinger


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.

like image 28
Po' Lazarus Avatar answered Oct 12 '22 05:10

Po' Lazarus