0

I am new to android development. I am using webview to display HTML pages in android, but only the text shows up. Can you please help me with the problem. thank you in advance, would be very helpful.

 WebView view = (WebView) this.findViewById(R.id.webView);
    try{

        InputStream stream = this.getAssets().open("Capacitor Code Calculator.html");
        int streamsize = stream.available();

        byte[] buffer = new byte[streamsize];
        stream.read(buffer);
        stream.close();
        String html = new String(buffer);
        view.loadData(html,"text/html", "utf-8");
    }
    catch (Exception e){
        e.printStackTrace();

Does it have to do something with "text/html" in view.loadData(html,"text/html", "utf-8");

I have my html and image file both in assets folder.

  • possible duplicate of [Referencing image in assets from HTML not working](http://stackoverflow.com/questions/9813646/referencing-image-in-assets-from-html-not-working) – Buddy Jun 29 '15 at 16:27

2 Answers2

0

It might be that you can't have spaces in your file name in the line:

InputStream stream = this.getAssets().open("Capacitor Code Calculator.html");

What is the url you're giving in the <img> tag? Do you have spaces in this name also?

Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106
0

WebView view = (WebView) this.findViewById(R.id.webview);

    view.getSettings().setJavaScriptEnabled(true);
    view.loadUrl(url);
    view.setWebViewClient(new WebViewClient());

The last setWebViewClient() displays the images .....finally relieved :) Hope it helps.