How to just open a directory / folder?

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

I have seen many similar topics, but in none of them have I found a solution. I need the simplest: in my application, I have a "View Media" button. After clicking this button, I need to open (with the built-in Explorer) this directory - SD_CARD / my_folder , where the multimedia files are located (and I want to click any of them, and they should be opened in the default Media Player).

I used all the suggested answers on SO, for example:

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 the button, the "Select File" menu opens: (When I can’t still play the media when I click)

enter image description here

+5
source share
1 answer

The solution (not complete) that I discovered was that I lacked the file:// prefix. Here is my solution (however it shows all kinds of applications in the 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); } 

ps It is strange and surprising, but there is no standard definition for "File Browser" in the warehouse of Android-systems (unless you install a third-party "Explorer"). This is why the "resource/folder" mime-type does not work by default .. (However, directory browsing is the main part of any OS, and it is very strange why Android does not have a default).

0
source

Source: https://habr.com/ru/post/1262690/


All Articles