5

According to the FileProvider documentation the fileProvider.openFile() method returns

a new ParcelFileDescriptor with which you can access the file.

I have looked in ParcelFileDescriptor, but I cannot see how to access the File. So how do I access the File from a ParcelFileDescriptor?

ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
  • use `ParcelFileDescriptor.AutoCloseInputStream`, what do you need `File` for? – pskink Jun 12 '17 at 07:24
  • 1
    Thanks. My app takes a photo and saves the Uri of the image which is stored in the database. I then need to get the File for that Uri so I can post the image to the server. Can you give me an example of how to use `ParcelFileDescriptor.AutoCloseInputStream`? – ban-geoengineering Jun 12 '17 at 07:51
  • just like any other `InputStream`, what kind of problems do you have with `PFD.ACIS`? – pskink Jun 12 '17 at 07:51
  • 2
    but honestly if you have `Uri` then simply use `ContentResolver#openInputStream`, not `FileProvider#openFile` – pskink Jun 12 '17 at 08:02
  • Yes, I've now gone with the `ContentResolver#openInputStream` approach (as described at https://stackoverflow.com/a/38028166/1617737). The FileProvider documentation is really lacking with this issue - many thanks for your help. If you'd like to provide it as a proper answer, please do and I will accept it. – ban-geoengineering Jun 12 '17 at 08:46
  • sure, no problem – pskink Jun 12 '17 at 08:54

0 Answers0