2011-08-14 5 views
3

私はZIPファイルのウェブサイトを持っています。私はそれをメモリ(ローカルディスクではなく)に解凍し、それをWebViewに表示したいと思います。このZIPファイルにはイメージのあるイメージディレクトリがあり、これらのファイルもWebViewからアクセス可能である必要があります。私は新しいContentProviderを作成することを考えていますが、私はこの場合どのようにするのか分かりません:)。Android:ZIPをメモリに抽出してWebView内にそのコンテンツを表示する

コード例を参考にしてください。 Thx!

答えて

1

あなたは2つのことを調べることができます:私は私のコンテンツでは、次のしているあなたのロジックhere

のベースとして新しいAPK拡張を使用してFileProvider

  • のようにパイプストリームを使用して

    1. プロバイダ:

      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()); 
      
      } 
      

      パイプストリーム:

      @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(); 
          } 
      } 
      
  • +0

    偉大な答えですが、EcoPipeDataWriterクラスは何ですか...?詳細を教えてください。 – fvisticot

    関連する問題