Android:将ZIP解压缩到内存中,并在WebView中显示其内容

Android:将ZIP解压缩到内存中,并在WebView中显示其内容,android,memory,zip,android-contentprovider,Android,Memory,Zip,Android Contentprovider,我有一个ZIP文件中的网站。我想在内存中解压它(而不是本地磁盘),然后在WebView中显示它。此ZIP文件具有包含图像的图像目录,WebView也可以访问这些文件。我正在考虑创建新的ContentProvider,但我不知道在这种情况下如何创建:) 请帮助编写示例代码。 谢谢 你可以研究两件事: 在中使用管道流 使用新的APK扩展作为逻辑基础 我的内容提供商中有以下内容: private ContentProvider.PipeDataWriter<ZipFile> pipe =

我有一个ZIP文件中的网站。我想在内存中解压它(而不是本地磁盘),然后在WebView中显示它。此ZIP文件具有包含图像的图像目录,WebView也可以访问这些文件。我正在考虑创建新的ContentProvider,但我不知道在这种情况下如何创建:)

请帮助编写示例代码。
谢谢

你可以研究两件事:

  • 在中使用管道流
  • 使用新的APK扩展作为逻辑基础
  • 我的内容提供商中有以下内容:

    private ContentProvider.PipeDataWriter<ZipFile> pipe = new EcoPipeDataWriter();
    
    @Override
    public AssetFileDescriptor openAssetFile(Uri uri, String mode)
            throws FileNotFoundException {
        ZipFile zip = getZip(uri);
                Bundle data = new Bundle();
                // put file name in bundle
        return new AssetFileDescriptor(openPipeHelper(uri, null, data, zip,
                pipe), 0, zip.getUncompressSize());
    
    }
    

    回答得很好,但是EcoPipeDataWriter类是什么?你能提供更多的细节吗?
    @Override
    public void writeDataToPipe(ParcelFileDescriptor output, Uri uri, String s, Bundle bundle, ZipFile zipFile) {
        final String filePath = bundle.getString(FILE_PATH_KEY);
    
        byte[] buffer = new byte[8192];
        FileOutputStream fout = new FileOutputStream(output.getFileDescriptor());
        try {
            // iterate throught zipfile until filenamea has been reach
    
            InputStream in = zipFile.getInputStream(fileHeader);
            int n;
            while ((n = in.read(buffer)) >= 0) {
                fout.write(buffer, 0, n);
            }
        } catch (ZipException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }