Android directory/folder 带有 Select 按钮的选择器

Android directory/folder picker with Select button

我是 android 编程新手,正在尝试使用 SAF 启动文件浏览器 select folder/directory。下面的代码在 select 文件时工作正常,但是,我希望用户 select 一个文件夹(and/or 创建一个新文件夹)。

  1. onActivityResult() 不会在 select 创建文件夹时被调用。是否可以触发此事件?
  2. 如何在文件资源管理器中获得 "select" 和 "new folder" 按钮,如附图所示?

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("*/*"); startActivityForResult(Intent.createChooser(intent, "Open folder"), PICK_REQUEST_CODE);

File explorer screenshot

I am new to android programming and trying to launch file explorer using SAF to select a folder/directory.

您的代码未使用存储访问框架。

however, I want user to select a folder (and/or create a new folder).

您不能为此使用 ACTION_GET_CONTENT。您需要使用 ACTION_OPEN_DOCUMENT_TREE,这需要 Android 5.0.