Open a file from archive without temporary extraction

后端 未结 1 1017
梦谈多话
梦谈多话 2020-12-20 01:34

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

相关标签:
1条回答
  • 2020-12-20 01:45

    In principle, you could create a ContentProvider that serves up the ZipInputStream.

    In this sample project I demonstrate how to create a ContentProvider supporting openFile() that uses a pipe created by ParcelFileDescriptor.createPipe() to serve up a file. createPipe() returns a pair (two-element array) of ParcelFileDescriptors representing the ends of the pipe. You use the second element out of the array to write to via an OutputStream; openFile() returns the first element out of the array to be passed by Android to the calling process. The caller would use openInputStream() to read in what you transfer via the pipe.

    In my case, I am sending an asset on which I get an InputStream via AssetManager. In your case, you would use your ZipInputStream.

    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().

    0 讨论(0)
提交回复
热议问题