androidstorage-access-framework

Can ACTION_OPEN_DOCUMENT look like the Files app?


I'm using ACTION_OPEN_DOCUMENT like this:

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
launcher.launch(intent);

The launcher using ActivityResultContracts.StartActivityForResult.

A picker appears, and the sidebar look like the same one you see in the Files app, showing Recent, Images, Documents, Downloads and SDCARD. This is good.

Now if I restrict it to only certain mime types by adding

intent.putExtra(Intent.EXTRA_MIME_TYPES, arraylist-of-my-types);

the sidebar looks quite different, only showing Images and Documents.

Is it possible to restrict the types without affecting the sidebar? The user will want to know where the document they choose is located, especially when using an external SD card.


Solution

  • TL;DR: No.

    A picker appears, and the sidebar look like the same one you see in the Files app, showing Recent, Images, Documents, Downloads and SDCARD.

    What the documents UI looks like will vary by device model, and there are tens of thousands of device models. The specific sidebar (or equivalent) options can vary by user. The documents UI also may not exist, especially for edge device types (watch, TV, car).

    Now if I restrict it to only certain mime types... the sidebar looks quite different, only showing Images and Documents.

    See above.

    Is it possible to restrict the types without affecting the sidebar?

    There may not be a sidebar. What appears in the sidebar (or any equivalent) is up to the developers of the document UI for that device model. You and I do not control it except in very general terms, and then not in any manner that is necessarily consistent across device models.