2015-01-07 58 views
1

當我想讓我的WebView加載需要Cookie的圖像時,我遇到了麻煩。WebView未使用Cookie來加載圖像

我已經設置了我的餅乾上的「CookieManager」

final android.webkit.CookieManager instance = android.webkit.CookieManager.getInstance(); 
instance.setAcceptCookie(true); 
instance.setCookie(".example.fr", mCookies, new ValueCallback<Boolean>() { 
    @Override 
    public void onReceiveValue(final Boolean value) { 
     loadWebView(); 
    } 
}); 

web視圖,然後加載自定義HTML字符串,因爲該應用程序正在生成正確的HTML。

private void loadWebView() { 
    // this string is an example of a generated HTML 
    String htmlContent = 
     "<!DOCTYPE html>" + 
     "<html><head>" + 
     "<link rel=\"stylesheet\" href=\"css/style.css\" type=\"text/css\" media=\"screen, projection\"/></head>" + 
     "<body><img src=\"www.example.fr/img.jpg\"/></body></html>"; 
    mWebView.loadDataWithBaseUrl("file:///android_asset/", htmlContent, "text/html", "UTF-8", null); 
} 

我想代理與查爾斯代理網絡電話和我注意到,請求www.example.fr/img.jpg沒有餅乾在頭設置。但是,當我使用Chrome debbuging檢查WebView時,我可以看到Cookies正確地位於資源選項卡下。

看起來它們不用於圖像下載。

任何提示或建議,使WebView使用Cookies進行資源下載?

謝謝。

回答