Load images using html <img> tag from Android expansion file

Luke Shim

I am trying to load my HTML files from Android expansion file(.obb) using WebView like

    String prompt = "";
    WebView webview = (WebView) rootView.findViewById(R.id.webview);

    try {
        InputStream html = getAssetFileDescriptor("www/" + mResult.getTitle() + ".html")
                .createInputStream();
        byte[] b = new byte[html.available()];
        html.read(b);
        prompt = new String(b);
        html.close();

    } catch (IOException e) {
        Log.e("Webview", "Couldn't open webpage");
    }

    webview.loadData(prompt, "text/html", "utf-8");

*getAssetFileDescriptor returns InputStream read by ZipResourceFile function(Zip file library)

It loads HTML into Webview successfully but all the images inside the HTML are not appearing.

I guess It's because it cannot access to image files through img tags.

for example, my html files have img tags like

<img src="./image1.jpg" />

Relative path seems not working because html and image files are zipped into obb file.

How can I fix it?

Yessine Mahdouani

You can mount the OBB file using StorageManager:

StorageManager storageManager = (StorageManager)app.getSystemService(Context.STORAGE_SERVICE);
boolean queued = storageManager.mountObb(<path>, null, new OnObbStateChangeListsner() {...});

Then, you can use this path to construct a path to your files: the returned path is the root to your OBB:

storageManager.getMountedObbPath(...) + "/image1.jpg";

an use that path to load your image

<img src="your_path" />

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

XDK - How to load an image from an URL in android using img tag

From Dev

Load script tag from the file html

From Dev

Get image from JSON file using JavaScript and display in HTML img tag

From Dev

Get image file name from HTML img tag by using RegEx in Notepad++

From Dev

Get image from JSON file using JavaScript and display in HTML img tag

From Dev

Remove <img> tag containing a word from Html string using PHP

From Dev

HTML <img src> wont load my images

From Dev

Trying to display images using <img> tag in XSLT

From Dev

Load Image in <img> tag using php

From Dev

How to retrieve and show images from another drive using src attribute in <img> tag?

From Dev

Dynamic url to load images from server using lazy list in android

From Dev

Trouble Using JavaScript to Insert HTML Img Tag

From Dev

Retrive the Url from an Html Img Tag

From Dev

SpringBoot: Why images are not loading html <img src> tag

From Dev

Display images through html img tag with angularjs and ionic

From Dev

Extract image src from <img>tag in android

From Dev

Extract image src from <img>tag android

From Dev

Retrieve image from JSON file which is in the database and display in HTML img tag

From Dev

Using xcassets images as src for img tag in a UIWebView web page

From Dev

Referencing images stored in object storage containers (Wirecloud) from img tag

From Dev

How to create an <img> tag in tooltip using names from the csv data file

From Dev

How to show images from json file using JQuery on an HTML Page?

From Dev

loading data from iframe tag in an html file using perl

From Dev

play video from www folder using html video tag ( on android )

From Dev

Load text from local .txt file into html textarea using JavaScript

From Dev

Load a Excel file with images using PHPExcel

From Dev

Load a Excel file with images using PHPExcel

From Dev

html tag <img> and <image>

From Dev

How to load images from html in the AsyncTask

Related Related

  1. 1

    XDK - How to load an image from an URL in android using img tag

  2. 2

    Load script tag from the file html

  3. 3

    Get image from JSON file using JavaScript and display in HTML img tag

  4. 4

    Get image file name from HTML img tag by using RegEx in Notepad++

  5. 5

    Get image from JSON file using JavaScript and display in HTML img tag

  6. 6

    Remove <img> tag containing a word from Html string using PHP

  7. 7

    HTML <img src> wont load my images

  8. 8

    Trying to display images using <img> tag in XSLT

  9. 9

    Load Image in <img> tag using php

  10. 10

    How to retrieve and show images from another drive using src attribute in <img> tag?

  11. 11

    Dynamic url to load images from server using lazy list in android

  12. 12

    Trouble Using JavaScript to Insert HTML Img Tag

  13. 13

    Retrive the Url from an Html Img Tag

  14. 14

    SpringBoot: Why images are not loading html <img src> tag

  15. 15

    Display images through html img tag with angularjs and ionic

  16. 16

    Extract image src from <img>tag in android

  17. 17

    Extract image src from <img>tag android

  18. 18

    Retrieve image from JSON file which is in the database and display in HTML img tag

  19. 19

    Using xcassets images as src for img tag in a UIWebView web page

  20. 20

    Referencing images stored in object storage containers (Wirecloud) from img tag

  21. 21

    How to create an <img> tag in tooltip using names from the csv data file

  22. 22

    How to show images from json file using JQuery on an HTML Page?

  23. 23

    loading data from iframe tag in an html file using perl

  24. 24

    play video from www folder using html video tag ( on android )

  25. 25

    Load text from local .txt file into html textarea using JavaScript

  26. 26

    Load a Excel file with images using PHPExcel

  27. 27

    Load a Excel file with images using PHPExcel

  28. 28

    html tag <img> and <image>

  29. 29

    How to load images from html in the AsyncTask

HotTag

Archive