使用Intent打开特定文件夹

Nik*_*Nik 5 android android-intent

我想使用Intent打开特定的路径文件夹,我使用File explorer的代码,它在一些设备(三星设备)中工作得很好,如果文件浏览器应用程序不可用,那么它不会打开特定路径的文件夹.我尝试了很多解决方案,但它对我不起作用.

Uri uri = Uri.fromFile(new File(new File(filePath).getParent()));
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "resource/folder");


        if (intent.resolveActivityInfo(getPackageManager(), 0) != null)
        {
            startActivity(intent);
        }
        else {

           Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
           intent.setDataAndType(uri, "file/*");
           startActivity(Intent.createChooser(intent, "Open folder"));

        }
Run Code Online (Sandbox Code Playgroud)

San*_*ush 2

        val intent = Intent(Intent.ACTION_GET_CONTENT)
        intent.setDataAndType(
            Uri.parse(
                (Environment.getExternalStorageDirectory().path
                        + java.io.File.separator) + "myFile" + java.io.File.separator
            ), "*/*"
        )
        intent.addFlags(
            Intent.FLAG_GRANT_READ_URI_PERMISSION
                    and Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                    and Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
                    and Intent.FLAG_GRANT_PREFIX_URI_PERMISSION
        )
        intent.addCategory(Intent.CATEGORY_OPENABLE)
        startActivityForResult(intent, WRITE_ACCESS_CODE)
Run Code Online (Sandbox Code Playgroud)