anjaneyulubatta505
anjaneyulubatta505

Reputation: 11665

I am unable to load an image in webview using html code with image url

I am trying to load an image and extracting some other details from a website in WebView from an url by inserting it in html code but when I try to load an image it shows nothing but an question symbol in WebView.

here is some part of the code

String htmlDetails(String extract) {
    String desc, link;
    String cost, model, ratings, specifications;

    Document document = Jsoup.parse(extract);
    extract = document.text();

    Elements description = document.select("a");
    Elements img = document.select("img[src]");

    Elements modelvalue = document.select("h2[class=a-size-base a-color-null s-inline s-access-title a-text-normal]");
    model = modelvalue.text().toString();

    Elements costvalue = document.select("div[class=a-row a-spacing-mini]");
    cost = costvalue.text().toString();

    Elements ratingvalue = document.select("div[class=a-row a-spacing-none]");
    ratings = ratingvalue.text().toString();

    Elements specificationvalue = document.select("ul[class=a-row a-spacing-top-mini a-spacing-mini]");
    specifications = specificationvalue.text().toString();

    desc = description.html();//attr("content");*/
    desc = img.attr("src").toString();

    desc = desc.substring(2);
    link = "http://10.0.2.2/andro/"+desc;

    String Html = "<html>"
            +"<body>"
            +"<img src='"+link+"' width='30px' height='50px'/>"
            +"</body>"
            +"</html>";
    return Html;
}

webview.lodaData(htmlDetails(HTML_String), "text/html", "UTF-8");

Upvotes: 3

Views: 974

Answers (1)

Mikhail Naganov
Mikhail Naganov

Reputation: 6861

A couple of hints:

Check if your app has INTERNET permission. WebView doesn't show any error messages, it just silently fails to load network stuff if you don't have this permission in your manifest:

<uses-permission android:name="android.permission.INTERNET" />

And you may need to use WebView.loadDataWithBaseUrl and specify your server's address in baseUrl argument:

webview.loadDataWithBaseUrl("http://10.0.2.2/", htmlDetails(HTML_String), "text/html", "UTF-8", null);

Upvotes: 1

Related Questions