How to open a file manager (with a given folder) that will not act as a file picker?

60 Views Asked by At

I am trying to open a file manager that will show the folder that I send to it via Intent. The file manager should act like a file manager and not a file picker, i.e. it will not return to my app once I decide to select a file from the given folder, but it will present standard options that are normally available when file manager is launched from the launcher icon.

I have tried the following:

        File   folder = getOutputFolder();
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        // I have tried: ACTION_VIEW, ACTION_GET_CONTENT, ACTION_OPEN_DOCUMENT

        Uri uri;
        if (Build.VERSION.SDK_INT >= 26) {

            String authority = getString(R.string.app_fileprovider);
            uri = FileProvider.getUriForFile(this, authority, folder);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else {
            uri = Uri.fromFile(folder);
        }

        // this with ACTION_GET_CONTENT, works as *picker* on API 28
        // on API 29 it does not open destination folder
        // intent.setData(uri); 

        intent.setDataAndType(uri, "*/*"); 
        // I have tried the following: image/*, file/*, */*, resource/folder
        // and DocumentsContract.Document.MIME_TYPE_DIR

        startActivity(Intent.createChooser(intent, getString(R.string.open_output_folder)));

All combinations that I have tried act as a file picker, and that's not what I am looking for. More than that, some combinations open the destination folder, some not. The behavior is different depending on API level as well.

Is there a standard way to achieve what I am looking for?

0

There are 0 best solutions below