0

我与这个问题斗争了很长时间,在谷歌和 SO 周围挖掘,但仍然没有运气。最后,我在这里得到您的帮助,请建议或帮助。

我对以下源代码的问题是它只显示图像不显示的字符串内容,而是显示白色矩形或有时带有问号的蓝色图像。

问:如何显示图像?

这是我的代码:

private void openURL() {

    DefaultHttpClient client = new HttpsRequest(getApplicationContext());
    HttpGet get = new HttpGet(getUrlField().getText().toString());
    // Execute the GET call and obtain the response
    HttpResponse getResponse;
    try {
        getResponse = client.execute(get);
        HttpEntity responseEntity = getResponse.getEntity();

        String content = EntityUtils.toString(responseEntity);
        getWebView().loadDataWithBaseURL(null, content, "text/html", "utf-8",
                null);

    } catch (ClientProtocolException e) {
        WSLog.e(THIS_FILE, "HTTP Error.");
        e.printStackTrace();
    } catch (IOException e) {
        WSLog.e(THIS_FILE, "Url Load Error.");
        e.printStackTrace();
    }
}

网络视图输出:

在此处输入图像描述

4

1 回答 1

1

在 Vasarat 的帮助下,我身边的一些修改帮助我回答了这个问题。我已将以下代码行修改为

getWebView().loadDataWithBaseURL("http://mywebSite.com/parent_dir_to_iamges/", content, "text/html", "UTF-8","about:blank");

这种修改给了我预期的完美输出。

请放松评论以了解有关该问题的详细信息。

注意:我在基本 url 中使用了 http 而不是 https .....如果我可以使用 https,请告诉我。 webview.Loadurl()如果 API 级别为 10 或更高,则使用 https url 可以正常工作,但它显示 API 级别 8 的空白页面。

于 2012-06-22T23:10:50.950 回答