Right now I’m working on an archive browsing application that lets users navigate through archive contents, extract the archives and preview the files inside the archive. I’m using java.util.zip API. To preview a file I’m extracting it temporarily and opening it as a usual existing file. As you may understand, that’s not a good approach since it won’t preview files if there’s not enough space to make a temporary extraction. Is there a working solution for passing ZipInputStream to an Activity to open it as a file? Is there another workaround for this problem? Thanks in advance.
Right now I’m working on an archive browsing application that lets users navigate through
Share
In principle, you could create a
ContentProviderthat serves up theZipInputStream.In this sample project I demonstrate how to create a
ContentProvidersupportingopenFile()that uses a pipe created byParcelFileDescriptor.createPipe()to serve up a file.createPipe()returns a pair (two-element array) ofParcelFileDescriptorsrepresenting the ends of the pipe. You use the second element out of the array to write to via anOutputStream;openFile()returns the first element out of the array to be passed by Android to the calling process. The caller would useopenInputStream()to read in what you transfer via the pipe.In my case, I am sending an asset on which I get an
InputStreamviaAssetManager. In your case, you would use yourZipInputStream.Note that my sample project assumes it is being run on a device that has a PDF viewer, since it is serving a PDF out of assets and trying to open it via
startActivity().