Apparently the "file picker" app does not completely implement the ACTION_OPEN_DOCUMENT_TREE intent.
Let's say this code is executed:
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.setType("vnd.android.document/directory");
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, OPEN_DIRECTORY_REQUEST_CODE);
This error is issued:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.OPEN_DOCUMENT_TREE cat=[android.intent.category.OPENABLE] typ=vnd.android.document/directory flg=0x43 }
the same with this alternative type "application/vnd.google-apps.folder"
or not including the line where the OPENABLE category is added
or using intent.setType(DocumentsContract.Document.MIME_TYPE_DIR);
while if this code is executed:
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivityForResult(intent, OPEN_DIRECTORY_REQUEST_CODE);
there are no errors but only disk roots are available for the user to choose, so the cloud space is not showed.
If the ACTION_OPEN_DOCUMENT is used like this:
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, OPEN_FILE_REQUEST_CODE);
cloud roots (only of Drive cloud domain, the only app that implements SAF, I think) are available and files can be selected.
I experimented and the Storage Access Framework is implemented. See for example this question:
Storage Access Framework - failing to obtain document tree from uri (returned from Drive app)
where you can see that the functionality exists, altough it is sort of a hack and refers to creating a folder, not selecting it (a folder should be a "document tree").
I think I have to find the right mime type so what could it be? I saw that many times there are erros when the intent has some wrong type or flag but when the right parameters are found it works.
Otherwise, how to officially ask Google to make the "file picker" app of SAF correctly implement the ACTION_OPEN_DOCUMENT_TREE intent for cloud domain, created by themselves for their own Storage Access Framework on Android? I hope it is already implemented, in fact.