问题
I read that I have to prepare my app in advance for Android Q release because then the common read/write access to files outside the app-owned directories could be deprecated, if they do not withdraw the new way of managing those files.
I have not so many lines of codes to change, luckily.
The fact is that the Storage Access Framework seems to have some issues. And it is here from Kitkat, I see (I did not know it). Otherwise my code is wrong.
I am not able to simply make the user choose a folder on the cloud storage so to get the Uri in return, to further populate that folder.
When I use the sample code found at
https://github.com/android/storage/tree/228c8e0aa19586bfcf36318ddb191719537a45a4/ActionOpenDocumentTree#action_open_document_tree
and put it in a basic activity app (the example default app created by the IDE), it happens that the user cannot select a cloud storage root but only disk locations. It is in Kotlin but I translated it to Java without altering it. Is it not a Java issue because I tried also the Kotlin version.
[ I wrote other code with some hacks that at least lead to having the cloud folder Uri back in the onActivityResult method. It encompasses using a different intent Action but it still does not serve my purposes, the middleware doesn't like it so it breaks Storage Access Framework - failing to obtain document tree from uri (returned from Drive app) ]
In both cases I have the same paths:
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="filesPath" path="/"/>
<external-path name="externalPath" path="/"/>
<external-files-path name="externalFilesPath" path="/"/>
</paths>
How to have the user select a folder on the cloud provider and how to get the uri?
回答1:
A DocumentsProvider
can choose whether or not to support ACTION_OPEN_DOCUMENT_TREE
and even ACTION_CREATE_DOCUMENT
with the flags FLAG_SUPPORTS_IS_CHILD and FLAG_SUPPORTS_CREATE respectively.
Google Drive does not, as of this time, support ACTION_OPEN_DOCUMENT_TREE
, so that's why it isn't able to be selected.
I believe Nextcloud supports ACTION_OPEN_DOCUMENT_TREE
, so that may help.
I wrote other code with some hacks that at least lead to having the cloud folder Uri back in the onActivityResult method. It encompasses using a different intent Action but it still does not serve my purposes, the middleware doesn't like it so it breaks Storage Access Framework - failing to obtain document tree from uri (returned from Drive app)
Yes. The URI returned is then passed to the provider (Google Drive in this case), which ultimately makes the decision of what documents to return. Since Drive doesn't support child relationships like this, it wouldn't work.
There's some more detail on this in Ian Lake's blog post Building a DocumentsProvider.
来源:https://stackoverflow.com/questions/56539920/storage-access-framework-doesnt-show-cloud-roots-when-using-action-open-documen