How to simply open directory/folder?

The solution (not complete) I have found, was that I was missing file:// prefix. Here is my solution (however, it shows all kinds of applications on first view):

public void openFolder(String location)
{
    // location = "/sdcard/my_folder";
    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri mydir = Uri.parse("file://"+location);
    intent.setDataAndType(mydir,"application/*");    // or use */*
    startActivity(intent);
}

p.s. Strange and surprising, but there doesnt exist the standard definition of "File Browser" in stock Android systems (unless you install 3rd party "File Explorer").. That's why "resource/folder" mime-type doesnt work by default..

However, let's say a simple truth. File-Browser is a SIMPLE and ESSENTIAL part of any OS system. And it's quite disrespectful from Android, saying that it's not their job, and throwing the responsiblity to 3rd party apps.


You can use type DocumentsContract.Document.MIME_TYPE_DIR which works on several devices and launches File Explorer. You can refer this SO for more details.

Tags:

Android