我知道如何创建一个Intent来选择一个文件:
public static Intent createGetContentIntent() {
// Implicitly allow the user to select a particular kind of data
final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
// The MIME data type filter
intent.setType("*/*");
// Only return URIs that can be opened with ContentResolver
intent.addCategory(Intent.CATEGORY_OPENABLE);
return intent;
}
但目前我希望用户只需浏览一个目录,然后在我的应用程序中读取所选目录。可能吗?谢谢!
答案 0 :(得分:0)
将a directory picker library添加到您的应用中,并允许用户选择一个目录。
或者,如果您的minSdkVersion
是21岁以上,则可以使用ACTION_OPEN_DOCUMENT_TREE
(the Storage Access Framework的一部分),只要您意识到用户没有选择目录而是内容树,您将使用DocumentFile
来处理生成的Uri
。