2012-06-22 41 views
0

我很長一段時間都在與這個問題作鬥爭,在Google和SO周圍挖掘,但仍然沒有運氣。最後,我在這裏得到你的幫助,請提供建議或幫助。loadDataWithBaseURL不會加載屬於html頁面的圖像

我與以下源代碼的問題是它只顯示字符串內容的圖像不顯示相反,它顯示白色矩形或有時帶問號的藍色圖像。

問:如何顯示圖像?

這裏是我的代碼:

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(); 
    } 
} 

webView的輸出:

enter image description here

+0

代替loadDataWithBaseURL中的第一個'null',您必須在其中放置getUrlField()。getText ).toString()' – vasart

+0

感謝您的回覆,但並未解決問題。我仍然看到相同的輸出。感謝您的建議。 – mask

+0

你知道存儲這個頁面的圖像的URL嗎?你必須把這個url作爲loadDataWithBaseURL中的第一個參數 – vasart

回答

1

隨着Vasarat的幫助和一些修改從我身邊幫我來回答這個問題。我已將以下代碼行修改爲

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

此修改爲我提供了預期的完美輸出。

請停用評論以瞭解有關此問題的詳細信息。

注意:我已經在基地址中使用http而不是https .....請讓我知道我是否可以使用https。 webview.Loadurl()如果API級別爲10或更高,但它顯示空白頁面爲API級別8,則可以正常工作。