我无法使用带有图片网址的html代码在webview中加载图片

时间:2021-09-19 05:51:14

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.

我试图通过插入html代码从URL中加载图像并从WebView中的网站中提取其他一些细节但是当我尝试加载图像时,它只显示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");

1 个解决方案

#1


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:

检查您的应用是否具有INTERNET权限。 WebView不会显示任何错误消息,如果您在清单中没有此权限,它就会无声地加载网络内容:

<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并在baseUrl参数中指定服务器的地址:

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

#1


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:

检查您的应用是否具有INTERNET权限。 WebView不会显示任何错误消息,如果您在清单中没有此权限,它就会无声地加载网络内容:

<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并在baseUrl参数中指定服务器的地址:

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