当我尝试打开特定文件夹时,仅打开最近的文件夹

时间:2019-01-08 04:42:48

标签: android directory

当我尝试打开特定文件夹时遇到问题,我有这段代码可以打开文件夹/myprojects/test1

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath() + "/myProjects/test1");
intent.setDataAndType(uri, "image/*");
startActivity(intent);

该代码只会为我打开一个最近的文件夹,在这里我可以看到我画廊中的所有照片,而没有打开特定的文件夹

我正在使用API​​ 26进行测试

enter image description here

2 个答案:

答案 0 :(得分:0)

尝试这样:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()
     +  File.separator + "/myFolder/" + File.separator);
intent.setDataAndType(uri, "resource/folder");
startActivity(Intent.createChooser(intent, "Open folder"));

请确保您的设备上安装了任何文件浏览器应用程序

答案 1 :(得分:0)

您应该更新以下行

intent.setDataAndType(uri, "image/*");

使用

intent.setDataAndType(uri, "resource/folder");
相关问题