Search code examples
androidandroid-intentstorage-access-framework

Android directory/folder picker with Select button


I am new to android programming and trying to launch file explorer using SAF to select a folder/directory. Below code works fine when selecting a file, however, I want user to select a folder (and/or create a new folder).

  1. onActivityResult() doesn't get invoked on selecting a folder. Is it possible to trigger this event?
  2. How to get "select" and "new folder" buttons in the file explorer as shown in the attached image?

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

File explorer screenshot


Solution

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

    Your code is not using the Storage Access Framework.

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

    You cannot use ACTION_GET_CONTENT for that. You would need to use ACTION_OPEN_DOCUMENT_TREE, and that requires Android 5.0.