用户如何选择(现有)文件夹(不是文件内)

时间:2016-10-30 21:28:43

标签: android file android-intent

我知道如何创建一个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;
}

但目前我希望用户只需浏览一个目录,然后在我的应用程序中读取所选目录。可能吗?谢谢!

1 个答案:

答案 0 :(得分:0)

a directory picker library添加到您的应用中,并允许用户选择一个目录。

或者,如果您的minSdkVersion是21岁以上,则可以使用ACTION_OPEN_DOCUMENT_TREEthe Storage Access Framework的一部分),只要您意识到用户没有选择目录而是内容树,您将使用DocumentFile来处理生成的Uri