【问题标题】:How we can use images from APK main expansion file?我们如何使用 APK 主扩展文件中的图像?
【发布时间】:2012-05-24 13:51:06
【问题描述】:

我在过去 2 天面临一个问题,我们如何在 Google Play 上上传大小超过 50Mb 的 .apk 文件,然后我找到了一种方法来从链接 http://developer.android.com/guide/market/expansion-files.html 上传带有 APK 扩展文件的 .apk 现在我最终成功了,但现在我遇到问题了如何从我的对象中的主扩展文件中读取文件,就像它是 .obb 格式一样

但现在可以使用主扩展文件中的 .mp3 文件,例如:

AssetFileDescripto assetFileDescriptor = zipResourceFile.getAssetFileDescriptor( 
  "assets/all_types_of_people1.mp3");
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource( assetFileDescriptor.getFileDescriptor(), 
  assetFileDescriptor.getStartOffset(),assetFileDescriptor.getLength());

但是我们如何将主扩展文件中的图像使用到 WebView 中呢?

【问题讨论】:

    标签: android apk expansion


    【解决方案1】:

    由于可以从 zipResourceFile 获取流,因此可以使用 BitmapFactory 从它们创建图像。

    InputStream is = zipResourceFile.getInputStream("myFilePath.jpg");
    BitmapFactory.Options bfo = new BitmapFactory.Options();
    bfo.inPreferredConfig = Bitmap.Config.ARGB_8888;
    Bitmap b = BitmapFactory.decodeStream(is, null, bfo);
    

    请注意,由于解码需要一些时间,因此您需要在 UI 线程之外执行此操作。

    【讨论】:

    • 从 OOB 文件访问 html 文件的任何线索,例如我们如何从 webview 访问 html 例如:WebView wv = (WebView)this.findViewById(R.id.splashWebView); wv.loadUrl("file:///android_asset/html_no_copy/test.html");或者如何解压或提取 OBB 文件中的所有数据?
    【解决方案2】:

    dagalpin 已经给出了如何获取 InputStream 的方法。

    读取您的 HTML 文件并将其转换为 UTF-8 字符串。

    并如下加载。

    
    // you can also load from an HTML string:
     String summary = "<html><body>You scored <b>192</b> points.</body></html>";
     webview.loadData(summary, "text/html", null);
     // ... although note that there are restrictions on what this HTML can do.
     // See the JavaDocs for loadData() and loadDataWithBaseURL() for more info.

    我没有测试过。但它似乎起作用了。

    【讨论】:

      【解决方案3】:

      使用 expansionfiles/myFilePath.jpg

      而不是仅使用图像名称

      InputStream is = zipResourceFile.getInputStream("expansionfile/myFilePath.jpg");

      【讨论】:

        猜你喜欢
        • 2012-08-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多