Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simply open directory/folder?

Tags:

android

DONT mark this as duplicate, before reading what I need.

I have seen many similar topics, but in none of them I've found solution. I need the simplest thing: In my application I have button "View Media Files". After clicking that button, i need to be opened (with built-in File Explorer) this directory - SD_CARD/my_folder where are media files (and I want to click any of them and they should be opened in default Media player)..

I have used all suggested answers on SO , like this:

    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri mydir = Uri.parse("/sdcard/Recorder_Videos");
    intent.setDataAndType(mydir, "*/*");
    startActivity(intent);

but all they do: after clicking button, it opens "Choose File" menu: (Where I cant still play media files when clicking)

enter image description here

like image 531
T.Todua Avatar asked Jan 12 '17 11:01

T.Todua


2 Answers

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.

like image 63
T.Todua Avatar answered Oct 11 '22 13:10

T.Todua


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.

like image 22
Sagar Avatar answered Oct 11 '22 15:10

Sagar