I use ACTION_OPEN_DOCUMENT_TREE to allow the user to choose a path and get SAF permissions, but intent ACTION_OPEN_DOCUMENT_TREEon some user devices results in messages like
No app available to complete this action
and similar messages or the opening of an empty activity chooser.
The API level of the affected users OS are between API level 23 and 25 (at the moment).
I thought this was an operation supported by default on Android versions above Lollipop, but seems I was wrong.
Is there any alternative other than bloat the App with a double file management one based on SAF and one based on the classic direct file-system access?
I hope it happens only for older version of Android which still can work with
WRITE_EXTERNAL_STORAGEpermission.In this case we still can work with
SAFand itsDocumentFileIntent(Intent.ACTION_OPEN_DOCUMENT_TREE).canBeHandled(packageManager)If
ACTION_OPEN_DOCUMENT_TREEis not supported then you can ask users to grantWRITE_EXTERNAL_STORAGEpermission, select some folder (File) to work with and then convert it toDocumentFileusingDocumentFile.fromFile(File)and returnedDocumentFilewill have Write permission just likeFilebut it only works for devices which still fully supportWRITE_EXTERNAL_STORAGESo all other logic in your app can be implemented using
DocumentFile. The problem is just getting initial parent folder to work with (only in this case you will needFileandWRITE_EXTERNAL_STORAGEifACTION_OPEN_DOCUMENT_TREEis not supported)p.s. we can use
WRITE_EXTERNAL_STORAGEup to Android 12 (SDK 32) withandroid:requestLegacyExternalStorage="true"flag for application at the manifest