I wish to be able to share some files (via a send intent) as a single compressed file, via FileProvider.
For the intent, all you do is add the
ArrayList<Uri> as a parameter, as such:
ArrayList<Uri> uris = MyFileProvider.prepareFileProviderFiles(...) sharingIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
A FileProvider can be used to deliver real files to outside apps.
I don't want to have some junk files (the compressed ones, which are meant just for sharing) in my app staying around without any purpose, in case the app that used them has finished, crashed or stopped for some reason.
What I've found
According to the API of FileProvider, I'm supposed to implement real files handling:
By default, FileProvider automatically returns the ParcelFileDescriptor for a file associated with a content:// Uri. To get the ParcelFileDescriptor, call ContentResolver.openFileDescriptor. To override this method, you must provide your own subclass of FileProvider.
So it returns a ParcelFileDescriptor, but according to all of the functions to create ParcelFileDescriptor , I need a real file:
Is it possible to have it offer a file that doesn't really exist, but is actually a compressed one of a different file/s? A stream of the zipped file, perhaps?
If this is not possible, is there any way for me to avoid having those junk files? Meaning that I would know for sure that it's safe to delete the compressed file/s that I've shared in the past?
If even that isn't possible, how could I decide when it's ok to delete them? Just putting them in the cache folder? I remember that the cache folder doesn't really automatically get handled nicely by the OS, removing old files when needed. Isn't it still correct?