Is it somehow possible to get a File
object from an DocumentFile
? With some small trick I can get the real path of the file, but the File
class is not allowed to read/write there...
I need to access media files from USB OTG or secondary storage and I need following functions:
- get exif data from images => I really need that for
- getting the location of the image
- getting the real creation date of the image
- actually, for displaying purpose, I need all exif data
- ability to rotate images (this would be possible by creating a temp image, delete the old one and rename the temp image)
Any idea on how to achieve that?
No.
Not reliably. After all, the Storage Access Framework does not require there to be an actual file. Various
DocumentProvider
implementations work off of cloud services, where the data is not stored locally on the device until needed. Beyond that, whatever approach that you are using is dependent upon internal implementation that may vary by device, let alone Android OS version. And, to top it off, you still cannot necessarily access the data even if you derive a path, as you may not have filesystem access to that location (e.g., files held on internal storage by theDocumentProvider
).Use the stream, along with EXIF code that can work with streams, such as this one or this one, found by searching the Internet for
android exif stream
.You don't have a choice to make a local copy, rotate the image, and then write the image back to the original
DocumentFile
using anOutputStream
. Whether that "local copy" is only in RAM, or needs to be an actual file on disk, depends a bit on how you were planning on rotating it.