I use ACTION_OPEN_DOCUMENT_TREE
to allow the user to choose a path and get SAF permissions, but intent ACTION_OPEN_DOCUMENT_TREE
on 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_STORAGE
permission.In this case we still can work with
SAF
and itsDocumentFile
Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).canBeHandled(packageManager)
If
ACTION_OPEN_DOCUMENT_TREE
is not supported then you can ask users to grantWRITE_EXTERNAL_STORAGE
permission, select some folder (File
) to work with and then convert it toDocumentFile
usingDocumentFile.fromFile(File)
and returnedDocumentFile
will have Write permission just likeFile
but it only works for devices which still fully supportWRITE_EXTERNAL_STORAGE
So 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 needFile
andWRITE_EXTERNAL_STORAGE
ifACTION_OPEN_DOCUMENT_TREE
is not supported)p.s. we can use
WRITE_EXTERNAL_STORAGE
up to Android 12 (SDK 32) withandroid:requestLegacyExternalStorage="true"
flag for application at the manifest