Search code examples
androidstorage-access-framework

DocumentFile.fromFile on 5.0+


In my testing I'm finding that any DocumentFile created with fromFile fails any write (createFile, createDirectory, etc) on 5.0+ even if you have permission to the root from the SAF.

Is this expected behavior?

If fromFile is ONLY for <5.0 compatibility I really wish they would have been clear on that in the documentation.


Solution

  • So fromFile generates a RawDocumentFile, which appears to simply wrap a file. I don't see how this would offer any additional write permission that the File itself would not have, regardless of SAF permission, so I'm going to say that fromFile should act solely as a backwards compatibility (<4.4) factory. I've submitted an enhancement request to update the documentation to explain this.