我正在保存WebView的内容,以便在下次启动我的应用程序时显示该内容。我遵循this这几乎是我想要的。WebView - 下载javascript,css和图像
@JavascriptInterface
public void setHtml(String html) {
SharedPreferences settings = getSharedPreferences("preferences", MODE_PRIVATE);
this.html = html;
SharedPreferences.Editor prefEditor = settings.edit();
prefEditor.putString("ActivityHtml", html);
prefEditor.commit();
Log.d("html", html);
setChanged();
notifyObservers(html);
}
然后:
view.loadDataWithBaseURL("", settings.getString("ActivityHtml", ""), "text/html", "UTF-8", "");
然而,当我看到在日志中的HTML中,Javascript和CSS有这样的服务器的路径:
<link href="/Content/Sass/style_sass.css?version=1.0.1.15" rel="stylesheet">
<img src="../Images/magnify_black.png" />
现在因为如此,才有了文本内容显示,而图像不显示。就像这样:
我怎么可能会在HTML的图像,CSS和JavaScript?
只是告诉我现在已经有以下几点:
view.getSettings().setLoadsImagesAutomatically(true);
view.getSettings().setJavaScriptEnabled(true);
您没有提供基本URL,因此WebView不知道在哪里查找资产。他们是否在APK中的“资产”文件夹中?如果是这样,'view.loadDataWithBaseURL(“file:/// android_asset”,...'。如果这些资源没有被下载到任何地方,您需要使用原始网站的URL作为基础 – CodingIntrigue
尝试从资产:通过使用'webView.loadDataWithBaseURL(“file:/// android_asset /”,yourdata,“text/html”,“UTF-8”,null);' –
@RGraham:你让我:)请发表一个答案。 – Nitish