Android:打开文件夹对话框

时间:2015-10-20 17:05:13

标签: android file directory

我有以下代码在Android中打开一个文件夹,虽然我看到很多帖子提到它有效但我无法让它工作。

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
File f = new File(Environment.getExternalStorageDirectory(),"myFolder");
Uri uri = Uri.fromFile(f);
intent.setDataAndType(uri, "*/*");
startActivity(Intent.createChooser(intent, "Open folder"));

它只打开根文件夹(在本例中为/ storage / sdcard而不是/ storage / sdcard / myfolder)。

任何人都知道为什么?

感谢

1 个答案:

答案 0 :(得分:1)

ACTION_GET_CONTENTdocumented使用Uri的{​​{1}}部分。虽然可能有一些应用程序的活动支持Intent,但许多应用程序不支持。{/ p>

此外,Android并不真正使用“文件夹”,因此设备上不一定会有任何应用程序,允许您浏览任意内容。

欢迎您在Android 4.4+上使用the Storage Access Framework,这是Google处理来自多个来源的用户浏览内容的中央系统用户界面的方法。

或者,有很多file and directory picker libraries for Android

相关问题