问题
USB mass storage is now officially supported by Android, exclusively through the Storage Access Framework. It does not seem to mount the storage in a typical sense, as far as I can tell the only way to access the data is through the Document API and ContentResolver
.
1) Is there no longer a simple File
way to access the storage after going through the SAF?
2) If not, what's the best way to interact with 'files' on USB storage in NDK if we don't have access to paths.
回答1:
There are a lot of flaws in the implementation of DocumentFile
, primarily as it relates to "tree" vs "document" uris and the fact that you cannot store a "tree" uri due to a huge bug in the factory, but also in the lack of 'parent' functionality, so I wrote a useful one, cleverly named UsefulDocumentFile
https://github.com/rcketscientist/DocumentActivity/blob/master/library/src/main/java/com/anthonymandra/framework/UsefulDocumentFile.java
UsefulDocumentFile
can stand on it's own, but the overall project is an attempt to patch the life-cycle snafu Google created with SAF (If you request write permission you interrupt the pending write action to open SAF which is awful HMI).
来源:https://stackoverflow.com/questions/34693645/android-6-0-usb-mass-storage