webview未加载图片

时间:2013-06-16 13:12:32

标签: android webview jsoup

需要将从url html数据加载到webview中。

我的代码

 private String getHtmlFromURLJsoup(String url) throws IOException{
            Document doc = Jsoup.connect(url)
                    .userAgent("Mozilla")
                    .cookie("auth", "token")
                    .timeout(10000)
                    .get();

            return doc.html();

    }

mWebView.loadUrl("javascript:(function () { " +
                "setMainContent('" + getHtmlFromURLJsoup(s).replaceAll("\n", "").replaceAll("'", "") + "');" +
                "})()");

内容加载正常,但图片未显示。如何从数据库(图像,样式,脚本......)加载来自url的html?

2 个答案:

答案 0 :(得分:1)

从WebView尝试此方法:

loadDataWithBaseURL(null, htmlBody, "text/html", "UTF-8", null);

htmlBody - 您的html下载数据。

还尝试在方法中将String更改为CharSequence:

private CharSequence getHtmlFromURLJsoup(String url) throws IOException{

答案 1 :(得分:0)

您是否在询问如何实施自己的网络浏览器?

html将链接到其他东西(图像,样式,脚本......) - 您需要在html中找到链接并单独获取它们 - 这就是Web浏览器的功能。